c - Any reason why a loop wouldn't terminate even with an 'i' limiting value of repeats? -
I'm doing this assignment for college, it should be quite simple, but this does not seem like a loop in it. If finished, the code will not work properly; Even if I put one in the value of the value, it limits the amount of the loop. Try it with a loop for it, it still gets stuck.
The code is considered to be in the values of coefficients and is trying to find the middle point between the two major values and to exclude the root for a cubic equation and to see if it is 0 If this does not happen, one of these borders should be changed to the midpoint value. Here is the relevant code:
int main (zero) {int i, u = 1000, l = -1000; Float A, B, C, D, Middle, Y; Scanf ("% f% f% f% f", & amp; a, & amp; b, & amp; c, & amp; d); While (stomach (U - L)> 0.001 & amp; amp; & amp; & amp; amp; & amp;; 10) {Medium = (U + L) / 2; Y = One * Pau (Middle, 3) + B * Pau (Middle, 2) + c * mid + d; If break (y == 0); And if (Y & lt; 0) L = Mid; And u = middle; I ++; } Printf ("\ nhere is a root: x =% .3f \ n", middle); } Any help would be appreciated, thanks!
Edit: Oh God, I'm stupid. Always the little things code is still not working, but at least now it's not stuck, thanks guys!
2 things start with 0 It will ensure that it ends after 10 loops. More important for your problem, however, you have declared Yu and L as integers, I think you have to declare them as Floats.
Comments
Post a Comment