fork download
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. const long double PI = acos(-1);
  6. const long int iters = 200;
  7.  
  8. double func(double x)
  9. {
  10. return (sin(x) + 1 - log(x));
  11. }
  12.  
  13. double rad2ang(double rad)
  14. {
  15. return 180*rad/PI;
  16. }
  17.  
  18. double find(double x0, double x1, double eps)
  19. {
  20. double left = x0, right = x1, x, f;
  21. int iter = 0;
  22. printf("x0 = %lf x1 = %lf ", x0, x1);
  23. do {
  24. x = (left + right) / 2;
  25. f = func(x);
  26. if (f < 0)
  27. right = x;
  28. else
  29. left = x;
  30. iter++;
  31. } while (fabs(f) > eps && iter < iters);
  32. printf("%d итераций\n", iter);
  33. return x;
  34. }
  35.  
  36. int main()
  37. {
  38. const long double eps = 1e-5;
  39. system("chcp 1251");
  40. system("cls");
  41. printf("%lf ", rad2ang(find(eps, 100.0, eps)));
  42. getchar();
  43. return 0;
  44. }
  45.  
Success #stdin #stdout #stderr 0s 4372KB
stdin
Standard input is empty
stdout
x0 = 0.000010 x1 = 100.000000 23 итераций
173.727100 
stderr
sh: 1: chcp: not found
sh: 1: cls: not found