calculating power of a number

/* Problem : sol4_3_2.c
Solution : */




#include
#include


void main()
{
double power(double,int);
double n,ans;
int p;
clrscr();

printf("\n\n\n\t\t\t Program for calculating power of a number");


printf("\n\n\n\t\t\t Enter the base number = ");
scanf("%lf",&n);

printf("\n\t\t\t Enter the power = ");
scanf("%d",&p);

ans=power(n,p);

printf("\n\n\t\t\t Result of %.2lf to power %d is %.2lf",n,p,ans);

getch();

}

double power(double nn,int pp)
{
if(pp==0)
return (1);
else
return(nn*power(nn,pp-1));
}

No comments:

Post a Comment