Translate

Labels

Tuesday, 2 April 2013

X TO THE POWER Y

#include<stdio.h>
#include<conio.h>
float power(int x,int y)
{
float p;
if(y==0)
return(1);
else if(y>0)
p=x*power(x,y-1);
else
{
p=1/power(x,-y);
}
return(p);
}
void main()
{
int x,y;
float p;
clrscr();
printf("Enter values of X and y \n");
scanf("%d%d",&x,&y);
p=power(x,y);
printf("%f",p);
getch();
}

OUTPUT
Enter values of X and Y
2
3
8.000000
Enter values of X and Y
2
-2
0.25
Enter values of X and Y
3
0
1

No comments: