problem no 7:Given two numbers A and B, find Kth digit from right of AB.

 QUESTION:

Given two numbers A and B, find Kth digit from right of AB.
 

Example 1:

Input:
A = 3
B = 3
K = 1
Output:
7
Explanation:
33 = 27 and 1st
digit from right is 
7

Example 2:

Input:
A = 5
B = 2
K = 2
Output:
2
Explanation:
52 = 25 and second
digit from right is
2.


ANSWER:

int kthDigit(int A,int B,int K){
     long long int num=pow(A,B);
     int count=0;
     int rem;
     while(num>0)
     {
        
          rem=num%10;
         
         num=num/10;
         count=count+1;
         if(count!=K)
         {
             continue;
         }
         else
         {
             break;
         }
     }
 
  return rem;
    }

Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

Problem no 16: count the number of squares below N.