Program to find power of a number:
In this program we are finding power of any number which will entered by the user and user will also enter a power. There is a function power which will return power of the number after calculating and Power function is taking two arguments number and power. While loop will run until power is not less than 1. After while loop will terminate the Power function will return the power of the number.
#include <stdio.h>
#include <math.h>
main()
{
int n,p,r;
printf("enter a number who's power you want to find");
scanf("%d",&n);
printf("enter any power");
scanf("%d",&p);
r=power(n,p); //passing number and power to Power function
printf("the result is %d",r);
}
int power(int num,int p) //Power function taking two arguments
{
int result=1;
//While Loop it will run till power is greater than or equal to 1
while(p>=1)
{
result*=num;
p--;
}
return result;
}
0 Comment(s)