forked from RajkumarSony/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitwise-operator.c
More file actions
44 lines (39 loc) · 829 Bytes
/
Bitwise-operator.c
File metadata and controls
44 lines (39 loc) · 829 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
38
39
40
41
42
43
44
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int max(int a, int b){
return a>b?a:b;
}
void calculate_the_maximum(int n, int k) {
int max_and=0, max_or=0, max_xor=0;
int and, or, xor, i, j;
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
and = i&j;
or = i|j;
xor = i^j;
if(and<k)
{
max_and = max(and, max_and);
}
if(or<k)
{
max_or = max(or, max_or);
}
if(xor<k)
{
max_xor = max(xor, max_xor);
}
}
}
printf("%d\n%d\n%d\n", max_and, max_or, max_xor);
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}