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.
#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>//Complete the following function.voidcalculate_the_maximum(intn,intk){intmax1=0,max2=0,max3=0;for(intj=1;j<=k;j++){for(inti=j+1;i<=n;i++){if((j&i)>max1&&(j&i)<k)max1=j&i;if((j|i)>max2&&(j|i)<k)max2=j|i;if((j^i)>max3&&(j^i)<k)max3=j^i;}}printf("%d\n%d\n%d",max1,max2,max3);}intmain(){intn,k;scanf("%d %d",&n,&k);calculate_the_maximum(n,k);return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bitwise Operators
You are viewing a single comment's thread. Return to all comments →