Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdlib.h>
- #include <math.h>
- #include <stdio.h>
- #include <errno.h>
- int extr_count(int a, int b); //Функция, вычисляющая количество локальных экстремумов на отрезке [a;b]
- void main()
- {
- double a, b;
- int k;
- printf("Enter\na = ");
- scanf("%lf", &a);
- printf("Enter\nb = ");
- scanf("%lf", &b);
- k = extr_count(a, b);
- printf("%i extremum points from a = %f to b = %f\n", k, a, b);
- system("pause");
- }
- int extr_count(int a, int b) //Функция, вычисляющая количество локальных экстремумов на отрезке [a;b]
- {
- int k = 0;
- double x, h = 0.000001, f_x, f_x_l, f_x_r;
- for(x = a + h; x < b; x += 0.000001)
- {
- f_x = cos(5 * x) - sin(3 * x);
- f_x_l = cos(5 * (x+h)) - sin(3 * (x+h));
- f_x_r = cos(5 * (x-h)) - sin(3 * (x-h));
- if ((f_x > f_x_l && f_x > f_x_r) || (f_x < f_x_l && f_x < f_x_r))
- {
- k++;
- }
- }
- return(k);
- }
Add Comment
Please, Sign In to add comment