+ 1
Can anyone explain the algorithm to find cube roots
2 Respuestas
+ 4
i would do it in this way:
i supose it is about finding the cube root of an int.
the number offered is
var num
i would declare a variable like this
var i = 0
then i will search using brute force for an answer
while (i < max_int/2)
if (i*i*i == num)
return i
increment i
if (i == max_int/2)
return "the number doesn't have an integer cube root"
something like that. it ain't much, but it's honest work
+ 3
I don't know if there is a way to find the cube root programmatically. But we can do it mathematically using logs.
The theory is,
cbrt(x) = antilog (1/3 lg x)
You can use this equation in your program to find the cube root
NOTE: There are methods find cbrt in some languages by default. But if you need to figure out the way I think this is the method