Wednesday 6 September 2017

Write a C program to find kth digit from right of a^b.


Given two numbers a and b, Write a C program to find kth digit from right of a^b. 

Program:



#include <stdio.h>
#include <math.h>
void kdigit(int);
main()
{
               int a,b;
               printf("enter two numbers");
               scanf("%d%d",&a,&b);
               kdigit(pow(a,b));
              
}
void kdigit(int n)
{
               int k,r;
               printf("enter k value");
               scanf("%d",&k);
               while(n>0 && k != 0)
               {
                              r=n%10;
                              n=n/10;
                              k--;
               }
              
               if((n<=0 && k != 0))
                              printf("kthdigit is not there");
               else
                              printf("kthdigit is %d",r);
              
}

No comments:

Post a Comment