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
Post a Comment