Recursive function to calculate x to the power n
| 14 | |
| 15 | // Recursive function to calculate x to the power n |
| 16 | double power(double x, int n) |
| 17 | { |
| 18 | if (n == 0) return 1.0; |
| 19 | else if (n > 0) return x * power(x, n - 1); |
| 20 | else /* n < 0 */ return 1.0 / power(x, -n); |
| 21 | } |