Program to find power of a number using recursion


Default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Write a program to find power of a number using recursion
// Eg: Eg: base:3, power:4-> 81

 
#include <stdio.h>
int power(int ,int );
int main()
{
    int base,pow;
    printf("Enter base:");
    scanf("%d",&base);
    printf("Enter power:");
    scanf("%d",&pow);
    printf("%d",power(base,pow));
    getch();
}
int power(int base,int pow){
    if(pow==1)
        return base;
    return base*power(base,pow-1);
}

No comments:

Post a Comment