DarkDevourer

Защита 12

Dec 6th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <errno.h>
  6.  
  7. int extr_count(int a, int b); //Функция, вычисляющая количество локальных экстремумов на отрезке [a;b]
  8.  
  9. void main()
  10. {
  11. double a, b;
  12. int k;
  13. printf("Enter\na = ");
  14. scanf("%lf", &a);
  15. printf("Enter\nb = ");
  16. scanf("%lf", &b);
  17. k = extr_count(a, b);
  18. printf("%i extremum points from a = %f to b = %f\n", k, a, b);
  19. system("pause");
  20. }
  21.  
  22. int extr_count(int a, int b) //Функция, вычисляющая количество локальных экстремумов на отрезке [a;b]
  23. {
  24. int k = 0;
  25. double x, h = 0.000001, f_x, f_x_l, f_x_r;
  26. for(x = a + h; x < b; x += 0.000001)
  27. {
  28. f_x = cos(5 * x) - sin(3 * x);
  29. f_x_l = cos(5 * (x+h)) - sin(3 * (x+h));
  30. f_x_r = cos(5 * (x-h)) - sin(3 * (x-h));
  31. if ((f_x > f_x_l && f_x > f_x_r) || (f_x < f_x_l && f_x < f_x_r))
  32. {
  33. k++;
  34. }
  35. }
  36. return(k);
  37. }
Add Comment
Please, Sign In to add comment