fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void) {
  5. int i;
  6. double a, b, c, d, e, x0,x1,f0,fPrime,temp;
  7.  
  8. scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &x0);
  9.  
  10.  
  11. for (i=0;i<=10000;i++){
  12.  
  13. scanf("%lf",&x0);
  14. f0 = a*(pow(x0,4)) + b*(pow(x0,3)) + c*(pow(x0,2)) + d*x0 + e;
  15.  
  16. a = 4.00*a;
  17. b = 3.00*b;
  18. c = 2.00*c;
  19.  
  20. fPrime = a*(pow(x0,3)) + b*(pow(x0,2)) + c*x0 + d;
  21. x1 = x0 - (f0/fPrime);
  22.  
  23. if (fabs(x0-x1)>0.001){
  24.  
  25. x1 = x0;
  26.  
  27. continue;
  28.  
  29.  
  30. }
  31.  
  32. if (fabs(x0-x1)<0.001){
  33.  
  34. break;
  35.  
  36. }
  37. }
  38. printf("%.2f\n",x0);
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
0.00