Monday, 14 October 2019

You are given two integers a and b. You need to find number of digits in element a (let us call it n) and print out maximum number obtained by doing xor of 10^n and k, where k lies from 1 to b

//You are given two integers a and b. You need to find number of digits in element a (let us call it n) and print out maximum number obtained by doing xor of 10^n and k, where k lies from 1 to b
#include<stdio.h>
#include<math.h>
int main() {
    int a,b,n=0,k,max=0,temp,t,i,c=0;
    scanf("%d%d",&a,&b);
    //n=log(a)+1;
    t=a;
    while(t)
    {
        n++;
        t=t/10;
    }
    //printf("number of digits=%d\n",n);
    t=1;
    for(i=1;i<=n;i++)
        t=t*10;
    //printf("10 to power of n=%d\n",t);
    for(k=1;k<=b;k++)
    {
       
        temp=t^k;
        if(max<temp)
            max=temp;
    }
    printf("%d",max);
}

No comments:

Post a Comment