Friday, March 7, 2014

WRITE A FUNCTION POWER THAT COMPUTE X RAISED TO THE POWER Y AND RETURN DOUBLE TYPE VALUE

#include<conio.h>
#include<stdio.h>
void main()
{
double power(int,int);
int n,p;
double r;
clrscr();
printf("enter the no and power\n");
scanf("%d%d",&n,&p);
r=power(n,p);
printf("%d to the power %d is %lf",n,p,r);
getch();
}

double power(int n,int p)
{
//double r=1;
int i;
//for(i=1;i<=p;i++)
for(i=1;i<p;i++)
{
//r=r*n;
n=n*n;
}
//return(r);
return(n);
}

No comments:

Post a Comment