+ 2
Cube root finder
I wrote a code that should find cube root of the number given as num1 without using Math functions. However it is just printing “3.0”. I am thinking that it could be a double float error but I couldn’t solve it. https://code.sololearn.com/cH0DlekxquDR/?ref=app
1 Odpowiedź
+ 3
The if statement line should be an if - else with x=x+c in the else code block
while (error>0.00001){
error=num1-(x*x*x);
if (error<0){
error=-1.000000*error;
x=x-c;
c=c/10.000000;
System.out.println(x);
}
else{
x=x+c;
}
}