#include <iostream> using namespace std; void power(int base, int exp); int main() { power(10, 2); power(10, -2); return 0; } void power(int base, int exp) { int i; if(exp < 0) return; /* Can't do negative exponents. */ i = 1; for( ; exp; exp--) i = base * i; cout << "The answer is: " << i; return; }
The answer is: 100