day 2 commit & changed day 1 filenames
This commit is contained in:
parent
d5f4f817c0
commit
703fcae148
6 changed files with 99 additions and 0 deletions
30
D2_power.cpp
Normal file
30
D2_power.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include <iostream>
|
||||
|
||||
int power(int n, int e) {
|
||||
if (n < 0 || e < 0) return -1;
|
||||
else if (e > 0) return n * power(n, e - 1);
|
||||
else return 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n, e;
|
||||
|
||||
std::cout << "Enter number: ";
|
||||
std::cin >> n;
|
||||
std::cout << "Enter exponent: ";
|
||||
std::cin >> e;
|
||||
|
||||
std::cout << "Ans: " << power(n, e) << std::endl;
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Example:
|
||||
*
|
||||
* 5^4
|
||||
*
|
||||
* 5 * 5^3 =
|
||||
* 5 * 5 * 5^2 =
|
||||
* 5 * 5 * 5 * 5^1 =
|
||||
* 5 * 5 * 5 * 5 * 5^0 = 625
|
||||
*/
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue