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.intand,or,xor,i,j;intsla=0,slo=0,slx=0;for(i=1;i<n;i++){for(j=i+1;j<=n;j++){and=i&j;or=i|j;xor=i^j;// assume largest is k and find second largest for and operation if(and<k&&and>sla){sla=and;}// assume largest is k and find second largest for or operationif(or<k&&or>slo){slo=or;}// assume largest is k and find second largest for xor operationif(xor<k&&xor>slx){slx=xor;}}}printf("%d\n",sla);printf("%d\n",slo);printf("%d\n",slx);}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 →
Passed all Testcases