x2311

Untitled

Jan 12th, 2022
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cmath>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. double Func(double x) {
  9.     if (x <= 0) {
  10.         return abs(x);
  11.     } else if (0 < x && x < 4) {
  12.         return sqrt(x);
  13.     } else {
  14.         return 2;
  15.     }
  16. }
  17.  
  18. int main() {
  19.     double x, y;
  20.     cout << "Function value table" << endl;
  21.     for (int i = 0; i < 21; i++) {
  22.         cout << "_";
  23.     }
  24.     cout << endl;
  25.     cout << ("| X\t |\t Y |\n");
  26.     for (int i = 0; i < 21; i++) {
  27.         cout << "_";
  28.     }
  29.     cout << endl;
  30.     for (double i = -2; i <= 8; i += 0.5) {
  31.         x = i * 0.25;
  32.         y = Func(x);
  33.         cout << "| " << (x >= 0 ? " " : "");
  34.         cout << fixed << setprecision(4);
  35.         cout << x;
  36.         cout << " | ";
  37.         cout << (y >= 0 ? " " : "");
  38.         cout << fixed;
  39.         cout << setprecision(4);
  40.         cout << y << " |" << endl;
  41.     }
  42.     for (int i = 0; i < 21; i++) {
  43.         cout << "_";
  44.     }
  45.     cout << endl;
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment