x2311

Untitled

Nov 14th, 2021
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cmath>
  4. #include <iomanip>
  5. using namespace std;
  6. //все делал по примеру, я не смотрел как вы переписали так что может что-то быть не так как вы написали
  7.  
  8. //тут я смотрю где находится х и подставляю условия
  9. double Func(double x){
  10.     if(x<=1){
  11.         return x;
  12.     }else if(1 < x && x <3 )return 1;
  13.     else return -x+4;
  14. }
  15. int main(){
  16.     //создаю 2 "бакса"
  17.     double x, y;
  18.     //создаю табличну "шапку"
  19.     cout << "Function value table"<< endl;
  20.     for(int i=0;i<21;i++){
  21.         cout << "_";
  22.     }
  23.     cout << endl;
  24.     cout << ("| X\t |\t Y |\n");
  25.     for(int i=0;i<21;i++){
  26.         cout << "_";
  27.     }
  28.     cout << endl;
  29.     //начало цикла
  30.     for(int i=0;i<=20;i++){
  31.         //задаю х
  32.         x = i*0.25;
  33.         //использую функцию
  34.         y = Func(x);
  35.         //выдаю ответ и вывожу результат
  36.         cout << "| " << (x>=0 ? " " :"") << fixed << setprecision(4) << x << " | "  << (y>=0 ? " " :"")<< fixed << setprecision(4) << y << " |" <<endl;
  37.     }
  38.     //дорисовую таблицу
  39.     for(int i=0;i<21;i++){
  40.         cout << "_";
  41.     }
  42.     cout << endl;
  43.     //конец
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment