C/C++

Помогите, пожалуйста. Нужно составить программу на Си

1 задание
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <string.h>
#define BUFF 12
double f(double x) {
if (fabs(x - 1) < 1e-5) return INFINITY;
return 2 * sin(x) / pow(1 - x, 2);
}
void show(size_t n, double x, double y, double dx) {
const char* msgs[] = {
"возрастает",
"неизменна",
"убывает",
"разрыв",
"нет данных",
};
char msg[BUFF];
if (dx == DBL_MAX) {
strncpy_s(msg, _countof(msg), msgs[4], strlen(msgs[4]));
dx = 0;
}
else if (y == INFINITY) strncpy_s(msg, _countof(msg), msgs[3], strlen(msgs[3]));
else if (fabs(dx) < 1e-5) strncpy_s(msg, _countof(msg), msgs[1], strlen(msgs[1]));
else if (dx < 0) strncpy_s(msg, _countof(msg), msgs[2], strlen(msgs[2]));
else strncpy_s(msg, _countof(msg), msgs[0], strlen(msgs[0]));
printf("%3u.%11.2lf%15.4lf%17s%15.4lf\n", n, x, y, msg, dx);
}
double input(const char* msg) {
double value;
printf(msg);
scanf_s("%lf", &value);
return value;
}
int main(void) {
double a, b, h, stop, prev;
unsigned n;
do {
a = input("a: ");
b = input("b: ");
} while (a > b);
h = input("h: ");
stop = b + h / 2;
prev = f(a);
n = 0U;
system("chcp 1251 > nul");
show(++n, a, prev, DBL_MAX);
for (double x = a + h; x < stop; x += h) {
double next = f(x);
double dx = next - prev;
if (prev == INFINITY) dx = DBL_MAX;
if (next == INFINITY) dx = INFINITY;
show(++n, x, next, dx);
prev = next;
}
system("pause > nul");
return 0;
}
АИ
Анафия Искаков
90 793
Лучший ответ