We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
‵‵‵c
void calculate_the_maximum(int n, int k) {
//Write your code here.
int maxAnd = 0, maxOr = 0, maxXor = 0;
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
int a = i & j;
int o = i | j;
int x = i ^ j;
if (a < k && a > maxAnd) {
maxAnd = a;
}
if (o < k && o > maxOr) {
maxOr = o;
}
if (x < k && x > maxXor) {
maxXor = x;
}
}
‵‵‵
}
printf("%d\n%d\n%d\n", maxAnd, maxOr, maxXor);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bitwise Operators
You are viewing a single comment's thread. Return to all comments →
‵‵‵c void calculate_the_maximum(int n, int k) { //Write your code here. int maxAnd = 0, maxOr = 0, maxXor = 0;
}