Thursday

Write a program using user defined function to calculate y raise to power x.

#include<stdio.h>
#include<conio.h>
int power(int,int);
void main()
{
int y,x,p;
printf("\n Enter values for y and x: ");
scanf("%d%d",&y,&x);
p=power(y,x);
printf("\n y raise to power x= %d",p);
getch();
}
int power(int y, int x)
{
int pw=1,i;
for(i=1;i<=x;i++)
pw=pw*y;
return pw;
}

No comments:

Post a Comment

Rahul-Notes