Calculate the power of a number using a recursive function
#include<stdio.h> next
#include<math.h>
float power(float n1 ,int n2);
float power(float n1,int n2)
{
if(n2 == 0)
return 1;
else
return n1 * power(n1,n2 - 1);
}
int main ()
{
float x;
int y;
printf("enter the number : ");
scanf("%f",&x);
printf("enter the exponent : ");
scanf("%i",&y);
printf("%.2f",power(x,y));
return 0;
}

0 comments:
Post a Comment