Advertisement
DasShelmer

3.6.19

Oct 13th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. double calculate(double x) {
  6.  
  7.     x = abs(x);
  8.     if (x < 2)
  9.         return sqrt(5 * pow(x, 2) + 5);
  10.     else if (x < 10)
  11.         return x / sqrt(5 * pow(x, 2) + 5);
  12.     else
  13.         return 0.0;
  14. }
  15. int main() {
  16.     setlocale(LC_ALL, "Russian");
  17.     double a, b, h;
  18.     long steps = 1;// Промежуточные шаги
  19.     cout << "Введите границы отрезка для x [a, b]: ";
  20.     cin >> a >> b;
  21.     cout << endl << "Введите значение шага (h): ";
  22.     cin >> h;
  23.     steps = (b - a) / h;
  24.     cout << endl << "Расчётное кол-во шагов: " << steps + 1 + ((b - a - h * steps == 0) ? 0 : 1) << endl;
  25.     cout << "     x    " << "    y" << endl;
  26.  
  27.     for (double x = a; x <= b; x += h) {
  28.         printf("%9.3lf", x);
  29.         double y = calculate(x);
  30.         printf("%9.3lf\n", y);
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement