c - I have a continuous loop and I cannot figure out what is wrong with it -
i have continuous loop in c code , cannot figure out why acting way. feel missing noticable here can't see reason. here segment of code causing loop:
while (err > 0.0000001) { if (err != 1.0) { bab = ((2.0*bab) + input/(pow(bab, 2)))/3.0; printf("the approximate cube root %.3lf\n", bab); err = input - bab; } else { bab = ((2.0*app) + input/(pow(app, 2)))/3.0; printf("the approximate cube root %.3lf\n", bab); err = input - bab; } } any appreciated.
bab (sooner or later) approximately cube root of input. set
err = input - bab; and test
while (err > 0.0000001) so if input > 1 + 3*1e-7 (roughly), difference input - cube_root(input) larger threshold.
you want set
err = abs(input - bab*bab*bab); to control quality of approximation cube root of input.
Comments
Post a Comment