Bitwise Operators | HackerRank
Problem Link :Bitwise Operators
Solution :
Develop by Samsus Salehin Sabbir
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- void calculate_the_maximum(int n, int k) {
- int maxAnd = 0;
- int maxOr = 0;
- int maxXor = 0;
- for (int i=1; i<=n; i++) {
- for (int j=i+1; j<=n; j++) {
- if (((i&j) > maxAnd) && ((i&j) < k)) {
- maxAnd = i&j;
- }
- if (((i|j) > maxOr) && ((i|j) < k)) {
- maxOr = i|j;
- }
- if (((i^j) > maxXor) && ((i^j) < k)) {
- maxXor = i^j;
- }
- }
- }
- printf("%d\n%d\n%d\n", maxAnd, maxOr, maxXor);
- }
- int main() {
- int n, k;
- scanf("%d %d", &n, &k);
- calculate_the_maximum(n, k);
- return 0;
- }
No comments