-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitwiseOperators.c
More file actions
37 lines (31 loc) · 821 Bytes
/
BitwiseOperators.c
File metadata and controls
37 lines (31 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Question link - https://www.hackerrank.com/challenges/bitwise-operators-in-c/problem?isFullScreen=true
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
int calculate_the_maximum(int n, int k) {
//Write your code here.
int and=0, or=0, xor=0;
for (int i=1; i<n; i++){
for (int j=i+1; j<=n; j++){
int a = i&j, b = i|j, c = i^j;
if (a < k && and < a){
and = a;
}
if (b < k && or < b){
or = b;
}
if (c < k && xor < c){
xor = c;
}
}
}
return printf("%d\n%d\n%d", and, or, xor);
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}