For example:
Assume number = 5
Power = 3
Result = 5*5*5 = 125
Ans:
#include<stdio.h>
int power(int , int );
int main()
{
int num,pow,res; //res = result
printf("Enter any number : ");
scanf("%d", &num);
printf("Enter power of number : ");
scanf("%d", &pow);
res = power(num,pow);
printf("%d's power %d = %d",num,pow,res);
return 0;
}
int power(int n, int p)
{
int r=1;
for(; p>=1; p--)
r = r*n;
return r;
}
No comments:
Post a Comment