M
mathon
hi,
i already posted an entry because of this problem, unfortunately i
havent solved it so far..
I have created a recursion for the calculation of the power like this:
But the problem ist that i should use this formula x^2n = x^n x^n in
any way in order to have a runtime of log(n).
I read in the previous posting something like i should use this:
Maybe someone could help me here once more in order to reach my final
aim...?
matti
i already posted an entry because of this problem, unfortunately i
havent solved it so far..
I have created a recursion for the calculation of the power like this:
Code:
[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 ist that i should use this formula x^2n = x^n x^n in
any way in order to have a runtime of log(n).
I read in the previous posting something like i should use this:
Code:
if (0 == n%2)
{
return (x^((n-1)/2))*(x^((n-1)/2))
}
else
{
return x*(x^((n-1)/2))*(x^((n-1)/2))
}
Maybe someone could help me here once more in order to reach my final
aim...?
matti