M
mathon
hi,
i develeoped a recursive function for the power and it works fine
But the problem is this function should have a runtime of log(n) and
therefore i should use this formula x^2n = x^n x^n in any way. does
maybe someone knows here how i can modifiy it to reach my aim...?
matti
i develeoped a recursive function for the power and it works fine
Code:
double power(double x, int n) {
if (n < 0)
return 1/power(x, -n);
else if (n == 0)
return 1.0;
else
return x * power(x, n-1);
}
But the problem is this function should have a runtime of log(n) and
therefore i should use this formula x^2n = x^n x^n in any way. does
maybe someone knows here how i can modifiy it to reach my aim...?
matti