This Program will produce Exponentiation by Recursion Function
Code:
#include<stdio.h>
#include<conio.h>
double power(int x, int y);
void main()
{
int p, n;
double Result;
clrscr();
printf("Enter Number (p): ");
scanf("%d", &p);
printf("Enter Power (n): ");
scanf("%d", &n);
Result = power(p, n);
printf("%d^%d is %.0lf", p, n, Result);
getch();
}
double power(int x, int y)
{
if (y == 0)
{
return 1;
}
else
{
return x * power(x, y-1);
}
}
|