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){intmax_xor=0,max_and=0,max_or=0,or=0,xor=0,and=0;for(inti=1;i<=n;i++){for(intj=i+1;j<=n;j++){or=i|j;and=i&j;xor=i^j;if(max_or<or&&k>or)max_or=or;if(max_xor<xor&&k>xor)max_xor=xor;if(max_and<and&&k>and)max_and=and;}}printf("%d \n%d \n%d \n",max_and,max_or,max_xor);}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 →