C program to Calculate the Power of a Number Using Recursion

C program to Calculate the Power of a Number Using Recursion

/* Source Code to calculate power using recursive function */

#include <stdio.h>
int power(int n1,int n2);
int main()
{
    int base, exp;
    printf("Enter base number: ");
    scanf("%d",&base);
    printf("Enter power number(positive integer): ");
    scanf("%d",&exp);
    printf("%d^%d = %d", base, exp, power(base, exp));
    return 0;
}
int power(int base,int exp)
{
    if ( exp!=1 )
        return (base*power(base,exp-1));
}

Comments

Popular posts from this blog

C Program to Display the ATM Transaction

Java programming language

Python Program to Print all Prime Numbers in an Interval