/* Laura Toma csci 107 Write a recursive method exp that raises a positive (> 0) integer to a non-negative (>= 0) power; i.e. exp(3,2) should return 9. To do this, it helps to think about exponentiation recursively. If we want to raise m to the n power, we can think as follows: m^n = 1 if n = 0 m^n = m x m^(n-1) if n>0 Suggested test inputs (correct answer after arrow): exp (3,2) ==> 9 exp(83,0) ==> 1 exp(124, 1)==> 124 exp(1,124) ==> 1 exp(5,4) ==> 625 exp(10,3) ==> 1000 */ #include /* compute recursively and return a^b */ int exp(int a, int b) { if (b<0) { cout << "sorry. only positive exponents" << endl; return 0; } //a^0 = 1 if (b==0) { return 1; } //else ..a^b = a * a^(b-1) return a * exp(a, b-1); } int main() { int m, n; cout << "enter m="; cin >> m; cout << "enter n="; cin >> n; cout << "m^n = " << exp(m,n) << endl; return 0; }