Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- //все делал по примеру, я не смотрел как вы переписали так что может что-то быть не так как вы написали
- //тут я смотрю где находится х и подставляю условия
- double Func(double x){
- if(x<=1){
- return x;
- }else if(1 < x && x <3 )return 1;
- else return -x+4;
- }
- int main(){
- //создаю 2 "бакса"
- double x, y;
- //создаю табличну "шапку"
- cout << "Function value table"<< endl;
- for(int i=0;i<21;i++){
- cout << "_";
- }
- cout << endl;
- cout << ("| X\t |\t Y |\n");
- for(int i=0;i<21;i++){
- cout << "_";
- }
- cout << endl;
- //начало цикла
- for(int i=0;i<=20;i++){
- //задаю х
- x = i*0.25;
- //использую функцию
- y = Func(x);
- //выдаю ответ и вывожу результат
- cout << "| " << (x>=0 ? " " :"") << fixed << setprecision(4) << x << " | " << (y>=0 ? " " :"")<< fixed << setprecision(4) << y << " |" <<endl;
- }
- //дорисовую таблицу
- for(int i=0;i<21;i++){
- cout << "_";
- }
- cout << endl;
- //конец
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment