Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
pmbhatiya authored Mar 12, 2020
1 parent bb5a8bc commit 3c9e5e3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bitwise-operator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
The first line of output contains the maximum possible value of A&B.

The second line of output contains the maximum possible value of A|B.

The second line of output contains the maximum possible value of A^B.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{
int n, k;
scanf("%d %d", &n, &k);
int mxAnd = 0, mxOr = 0, mxXor = 0;

for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
if(mxAnd < (i & j) && (i & j) < k)
mxAnd = i & j;
if(mxOr < (i | j) && (i | j) < k)
mxOr = i | j;
if(mxXor < (i ^ j) && (i ^ j) < k)
mxXor = i ^ j;
}
}
printf("%d\n", mxAnd);
printf("%d\n", mxOr);
printf("%d\n", mxXor);

return 0;
}

0 comments on commit 3c9e5e3

Please sign in to comment.