fork(1) download
  1. #include <iostream>
  2.  
  3. double power(double x, int y)
  4. {
  5. if (y == 0)
  6. return 1;
  7. else if (y > 0)
  8. return x * power(x, y - 1);
  9. else
  10. return (1 / x) * power(x, y + 1);
  11. }
  12.  
  13. int main()
  14. {
  15. std::cout << power(2, 5) << std::endl;
  16. std::cout << power(2.5, 3) << std::endl;
  17. std::cout << power(2, -5) << std::endl;
  18. }
Success #stdin #stdout 0s 4312KB
stdin
Standard input is empty
stdout
32
15.625
0.03125