C Program to Find Power Using Recursive Function


This program evaluates baseexponent using recursive call in C programming language.

Recursive Function to Evaluate Power


#include<stdio.h>

int power(int, int);

int main()
{
    int base, exponent, result;

    printf("Enter base and exponent:\n");
    scanf("%d%d", &base, &exponent);

    /* Normal Function Call */
    result = power(base, exponent);

    printf("%d to the power %d is %d.", base, exponent, result);
    return 0;
}

int power(int x, int y)
{
    if(y==0)
    {
        return 1;
    }
    else
    {
        /* Recursive Function Call */
        return x * power(x, y-1);
    }
}

Output

Enter base and exponent:
13
5
13 to the power 5 is 371293.