C Program to Calculate Power Using Recursion - Source Code, Output & Execution Flow

C Program to Calculate Power Using Recursion

This C program calculates power using recursion.

#include <stdio.h>
long long power(int base, int exp) {
    if (exp == 0) return 1;
    return base * power(base, exp - 1);
}
int main() {
    int base, exp;
    printf("Enter base and exponent: ");
    scanf("%d %d", &base, &exp);
    printf("Result = %lld
", power(base, exp));
    return 0;
}
Enter base and exponent: 2 5
Result = 32

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.