main( )
{ int x,y; /*input data */
double power(int, int); /* prototype declaration*/
printf(“Enter x,y:”);
scanf(“%d %d” , &x,&y);
printf(“%d to power %d is %f\n”, x,y,power (x,y));
}
double power (int x, int y);
{
double p;
p = 1.0 ; /* x to power zero */
if(y >=o)
while(y--) /* computes positive powers */
p *= x;
elsewhile (y++) /* computes negative powers */
p /= x;
return(p);
}
Output
Enter x,y:162
16 to power 2 is 256.000000
Enter x,y:16-2
16 to power -2 is 0.003906