Write a program to calculate x raise to y or power(x,y) using while loop.
Code for Program to calculate x raise to y or power(x,y) using while loop in C Programming
#include<stdio.h> #include<conio.h> #include<math.h> #include<string.h> void main() { int x,y; double power(); clrscr(); printf("Enter value of x : "); scanf("%d",&x); printf("Enter value of y : "); scanf("%d",&y); printf("%d to power %d is = %f\n",x,y,power(x,y)); getch(); } double power(x,y) int x,y; { double p; p=1.0; if(y>=0) while(y--) p*=x; elsewhile(y++) p/=x; return(p); }
No comments:
Post a Comment