-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.cpp
More file actions
46 lines (36 loc) · 1.11 KB
/
7.cpp
File metadata and controls
46 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <iomanip>
#include <cmath>
void solve() {
double a, b, c, x_start, x_end, dx;
std::cout << "Введите a, b, c: ";
std::cin >> a >> b >> c;
std::cout << "Введите Xнач, Xкон, шаг dX: ";
std::cin >> x_start >> x_end >> dx;
if (dx <= 0) {
std::cout << "Ошибка: шаг dX должен быть положительным!" << "\n";
return;
}
std::cout << "\n" << std::string(40, '-') << "\n";
std::cout << std::setw(15) << "x" << std::setw(15) << "F(x)" << "\n";
std::cout << std::string(40, '-') << "\n";
std::cout << std::fixed << std::setprecision(4);
for (double x = x_start; x <= x_end + 1e-9; x += dx) {
double F;
if (x + c < 0 && fabs(a) > 1e-9) {
F = -a * pow(x, 3) - b;
}
else if (x + c > 0 && fabs(a) < 1e-9) {
F = x - a;
}
else {
F = x - c;
}
std::cout << std::setw(15) << x << std::setw(15) << F << "\n";
}
std::cout << std::string(40, '-') << "\n";
}
int main() {
solve();
return 0;
}