Advertisement
kxcoze

lab?_??

Mar 11th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;    
  4.  
  5. double power(double a, int n) {
  6.     double x = 1;
  7.     if (n > 0) {
  8.         for (int i = 0; i < n; i++) {
  9.             x *= a;
  10.         }  
  11.     } else if (n < 0) {
  12.         for (int i = 0; i < abs(n); i++) {
  13.             x /= a;
  14.         }  
  15.     }  
  16.      
  17.     return x;
  18. }
  19.  
  20. int main() {    
  21.     double ans;
  22.     int n;
  23.     cin >> ans >> n;
  24.     cout << power(ans, n) << '\n';
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement