C Program to Find the Power of a Number Using Functions
Subject: PPS (Programming for Problem Solving)
Contributed By: Sanjay
Created At: February 3, 2025
Question:
Write a C Program to Find the Power of a Number Using Functions
Explanation Video:

Explanation:
power(base, exponent) calculates base^exponent using recursion.
The base case is when exponent == 0, returning 1.
Otherwise, multiply base by power(base, exponent - 1).
Source Code:
#include <stdio.h>
int power(int base, int exponent) {
if (exponent == 0)
return 1;
else
return base * power(base, exponent - 1);
}
int main() {
int base, exponent;
printf("Enter base and exponent: ");
scanf("%d %d", &base, &exponent);
printf("%d^%d = %d\n", base, exponent, power(base, exponent));
return 0;
}
Input:
Enter base and exponent: 2 3
Output:
2^3 = 8