Advertisement
karbaev

QuickPow

Nov 30th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double quickPow(double a, int n){
  5.     double res = 1;
  6.     while(n){
  7.               if(n % 2 == 1){
  8.                    res *=a;
  9.               }
  10.               n/=2;
  11.               a*=a;
  12.     }
  13.     return res;
  14. }
  15. int main()
  16. {
  17.     double a;
  18.     int n;
  19.     cin>>a>>n;
  20.     double x=quickPow(a,n);
  21.     cout<<x;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement