fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double f(double x) {
  5. return x - 0.2 * (pow(x, 2) + 6);
  6. }
  7.  
  8. double solve(double x0, double eps) {
  9. double x = x0;
  10. int iter = 0;
  11.  
  12. while (fabs(0.2 * (pow(x, 2) + 6) - x) > eps) {
  13. x = 0.2 * (pow(x, 2) + 6);
  14. iter++;
  15. }
  16.  
  17. printf("Итераций: %d\n", iter);
  18. return x;
  19. }
  20.  
  21. int main() {
  22. double x0 = 0;
  23. double eps =1e-20;
  24. double root = solve(x0, eps);
  25.  
  26. printf("Решение: x = %lf\n", root);
  27. printf("Значение f(x) = %lf\n", f(root));
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Итераций: 150
Решение: x = 2.000000
Значение f(x) = 0.000000