Pages

Thursday, 17 August 2017

Power of number using function

Q: Write a ‘C’ program to find the power of number using function.?

Solution :


#include<stdio.h>
int power(int,int);
void main()
{
     int n,p;
     printf("Enter number>> ");
     scanf("%d",&n);

     printf("Enter power>> ");
     scanf("%d",&p);
     printf("\n\tPower\t%d",power(n,p));
    
}
int power(int n,int p)
{
     int result=1;
     while(p>0)
     {
          result=result*n;
          p--;
     }
     return result;
}


No comments:

Post a Comment