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 <= 0) {
- return abs(x);
- } else if (0 < x && x < 4) {
- return sqrt(x);
- } else {
- return 2;
- }
- }
- int main() {
- 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 (double i = -2; i <= 8; i += 0.5) {
- x = i * 0.25;
- y = Func(x);
- cout << "| " << (x >= 0 ? " " : "");
- cout << fixed << setprecision(4);
- cout << x;
- cout << " | ";
- cout << (y >= 0 ? " " : "");
- cout << fixed;
- cout << setprecision(4);
- cout << y << " |" << endl;
- }
- for (int i = 0; i < 21; i++) {
- cout << "_";
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment