C program to calculate the power of an input number using a user-defined function
#include<stdio.h>
#include<conio.h>
int power(int, int );
main()
{
int y,x,p;
printf("Enter the value of y\n");
scanf("%d",&y);
printf("Enter the value of x\n");
scanf("%d",&x);
p=power(y,x);
printf("y raise to power x=%d",p);
getch();
}
int power(int y,int x)
{
int p=1,i;
for(i=1;i<=x;i++)
{
p=p*y;
}
return p;
}
No comments:
Post a Comment