-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitwise.c
51 lines (45 loc) · 972 Bytes
/
bitwise.c
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
45
46
47
48
49
50
51
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
void calculate_the_maximum(int, int);
int main() {
int n, k;
scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}
void calculate_the_maximum(int n,int k)
{
static int fand,finalor,fxor,or,and,xor,o,x;
for(int s = 1;s <= n;s++)
{
//and operator
for (int a = s+1;a <=n;a++)
{
and = s&a;
if(and <k &&and >fand)
{
fand = and;
}
}
for (o = s+1;o <= n;o++)
{
or = s|o;
if(or<k && or > finalor)
{
finalor = or;
}
}
for (x = s+1;x <=n;x++)
{
xor = s^x;
if(xor<k && xor >fxor)
{
fxor = xor;
}
}
}
printf("%d\n%d\n%d",fand,finalor,fxor );
}