C and C++

Write a program using recursion to find power of a number

We can write,
nm = n*nm-1
=n*n*nm-2
=n*n*n*……………m times *nm-m

The program which implements the above logic is as follows:

#include<stdio.h>
int power(int,int);
void main()
{
int n,m,k;
printf(“Enter the value of n and m”);
scanf(“%d%d”,&n,&m);
k=power(n,m);
printf(“The value of nm
for n=%d and m=%d is %d”,n,m,k);
}
int power(int x, int y)
{
if(y==0)
{
return 1;
}
else
{
return(x*power(x,y-1));
}
}
Output:
Enter the value of n and m
3
5
The value of nm
for n=3 and m=5 is 243