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.
Bitwise Operators
Bitwise Operators
Sort by
recency
|
492 Discussions
|
Please Login in order to post a comment
void calculate_the_maximum(int n, int k) { int a, b, c, max1=0, max2=0, max3=0; for(int i=1; i a=i & j; b=i | j; c=i ^ j; if(amax1) max1=a;
if(bmax2) max2=b;
if(cmax3) max3=c;
} } printf("%d\n%d\n%d", max1, max2, max3); }
a bit verbose in the inner cycle but it works;
int maxAND = 0, maxOR = 0, maxXOR = 0; for(int i= 1 ; i <= n; i++){ for(int j = i+ 1 ; j <= n && i <= n; j++){ int and = j&i; int or = j|i; int xor = j^i; if(and>maxAND && andmaxOR && ormaxXOR && xor
}
}
Little nooby, but otherwise working: