Program to calculate power using recursion
C Programming Language Recursion in c (Article) Recursion in c (Program)
880Program:
#include int power(int n1, int n2); int main() { int base, powerRaised, result; printf("Enter base number: "); scanf("%d",&base); printf("Enter power number(positive integer): "); scanf("%d",&powerRaised); result = power(base, powerRaised); printf("%d^%d = %d", base, powerRaised, result); return 0; } int power(int base, int powerRaised) { if (powerRaised != 0) return (base*power(base, powerRaised-1)); else return 1; }
Output:
Enter base number: 3 Enter power number(positive integer): 4 3^4 = 81
Explanation:
None
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.