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){//Write your code here.intmaxAND=0,maxOR=0,maxXOR=0;for(inta=1;a<n;a++){for(intb=2;b<n+1;b++){if(b!=a){maxAND=(maxAND<(a&b)&&(a&b)<k)?(a&b):maxAND;maxOR=(maxOR<(a|b)&&(a|b)<k)?(a|b):maxOR;maxXOR=(maxXOR<(a^b)&&(a^b)<k)?(a^b):maxXOR;}}}printf("%d\n%d\n%d\n",maxAND,maxOR,maxXOR);}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 →