Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- double calculate(double x) {
- x = abs(x);
- if (x < 2)
- return sqrt(5 * pow(x, 2) + 5);
- else if (x < 10)
- return x / sqrt(5 * pow(x, 2) + 5);
- else
- return 0.0;
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- double a, b, h;
- long steps = 1;// Промежуточные шаги
- cout << "Введите границы отрезка для x [a, b]: ";
- cin >> a >> b;
- cout << endl << "Введите значение шага (h): ";
- cin >> h;
- steps = (b - a) / h;
- cout << endl << "Расчётное кол-во шагов: " << steps + 1 + ((b - a - h * steps == 0) ? 0 : 1) << endl;
- cout << " x " << " y" << endl;
- for (double x = a; x <= b; x += h) {
- printf("%9.3lf", x);
- double y = calculate(x);
- printf("%9.3lf\n", y);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement