forked from nayyyhaa/C-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursiveExponents.cpp
More file actions
52 lines (29 loc) · 768 Bytes
/
recursiveExponents.cpp
File metadata and controls
52 lines (29 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
using namespace std;
int power(int base, int exp)
{
if( exp == 0)
return 1;
int product ;
product = base * power(base, exp-1);
return product;
}
int main()
{
int exp;
int base;
int product;
char answer;
cout << " Type in a base: ";
cin >> base;
cout << " Now type in an exponent: ";
cin >> exp;
while(exp < 0)
{
cout << " Invalid Input \n\n Please enter a positive number: ";
cin >> exp;
}
product = power(base, exp);
cout << " " << base << " raised to " << exp << " equals " << product << endl;
return 0;
}