fork(2) download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. double PowR(double x, unsigned int N)
  7. {
  8. if (N == 0) return 1;
  9. else if (N%2 == 0)
  10. {
  11. double z = PowR(x,N/2);
  12. return z*z;
  13. }
  14. else
  15. return x*PowR(x,N-1);
  16. }
  17.  
  18. double PowI(double x, unsigned int N)
  19. {
  20. double res = 1.0;
  21. while(N)
  22. {
  23. if (N%2) res *= x;
  24. x = x*x;
  25. N /= 2;
  26. }
  27. return res;
  28. }
  29.  
  30. int main()
  31. {
  32. for(unsigned int i = 0; i < 16; ++i)
  33. cout << setw(2) << i << setw(10) << PowR(2,i) << setw(10) << PowI(2,i) << "\n";
  34. }
  35.  
  36.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
 0         1         1
 1         2         2
 2         4         4
 3         8         8
 4        16        16
 5        32        32
 6        64        64
 7       128       128
 8       256       256
 9       512       512
10      1024      1024
11      2048      2048
12      4096      4096
13      8192      8192
14     16384     16384
15     32768     32768