C Program for User Defined Power Function
Write a c program to implement a user defined power function. A power function takes two parameters x and y and calculates xy.
C Program for User Defined Power Function
C Program
/* Aim: Write a function for the following function prototype int power(int x, int y) */ #include<stdio.h> int power(int x, int y); // Function Prototype void main() { int x,y; printf("\n Enter any value and power:- "); scanf("%d%d",&x,&y); 	:printf("\n The value of %d^%d is %d \n \n",x,y,power(x,y)); } // Power Function int power(int x, int y) { 	:int i,prod=1; 	:for(i=1;i<=y;i++) 	:{ 	:prod*=x; 	:} 	:return prod; } // End of the code
Output
/* Output of above code:-
Enter any value and power:- 4 2
The value of 4^2 is 16 */
Comments