Advertisement
TwITe

Stepik_Task_9

Jul 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. //goo.gl/qkHU4Q
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. double power(double a, int n) {
  6.     if (n < 0) {
  7.         return 1 / power(a, -n);
  8.     }
  9.     if (n == 0) {
  10.         return 1;
  11.     }
  12.     return a * power(a, n - 1);
  13. }
  14.  
  15. int main() {
  16.     double a;
  17.     int n;
  18.     cin >> a >> n;
  19.     cout << power(a, n);
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement