Problem: 1>. If the program iterates, the value of a will not change, which will cause the value of x to always be the input value. It should be written as x = ((2.0) / 3)*x + a / (3 * x*x); //将 x=a 放在do语句之前 2>. The value of (2/3) is 0. If you want to calculate floating point numbers, it should be written as (2.0/3) The above two are program errors.
while(fabs(a-x) < 0.00001);
Problem: 3>. The bool value returned after the first iteration of the judgment condition of the while statement is 0, and the loop is jumped out at this time.
If there is anything wrong with your answer, thank you for pointing it out
Update: Please also pay attention to the boundary conditions. If my value is 0, it needs to be processed separately
Problem:
1>. If the program iterates, the value of
a
will not change, which will cause the value ofx
to always be the input value. It should be written asx = ((2.0) / 3)*x + a / (3 * x*x); //将 x=a 放在do语句之前
2>. The value of
(2/3)
is 0. If you want to calculate floating point numbers, it should be written as(2.0/3)
The above two are program errors.
while(fabs(a-x) < 0.00001);
Problem:
3>. The bool value returned after the first iteration of the judgment condition of the while statement is 0, and the loop is jumped out at this time.
If there is anything wrong with your answer, thank you for pointing it out