/* title: RecursiveExponentiation author: aeriqusyairi date: Jan24 2012 */ #include<stdio.h> int power(int, int); int main(){ int number = 0, toPower = 0; printf("Enter base:"); scanf("%d", &number); printf("Enter exponent:"); scanf("%d", &toPower); printf("%d to the power of %d is %d.\n", number, toPower, power(number, toPower)); system("pause"); return 0; } int power(int base, int exponent){ if(exponent == 1) return base; else return base * power(base, exponent - 1); }
My C Repository
C How to Program
Sweet thanks to my broski Yusuke Fiz for this Deitel book.
You light up my life dude.
Just another personal public repository.
Thursday, March 15, 2012
Recursive Exponentiation
Program below is similar to the previous exponentiation program except the function execute recursively.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment