Advertisement
SonicDesu

Adamowe zagadki #2

Oct 15th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     double a{}, b{}, c{}, x{};
  7.  
  8.     cout << "***********************" << endl;
  9.     cout << "Podaj a =";
  10.     cin >> a;
  11.     cout << "Podaj b =";
  12.     cin >> b;
  13.     cout << "Podaj c =";
  14.     cin >> c;
  15.     cout << "***********************" << endl;
  16.     cout << "Podaj x = ";
  17.     cin >> x;
  18.     cout << "***********************" << endl;
  19.  
  20.     if (a < 0) {
  21.         if (a == -1)
  22.             cout << "-x^2";
  23.         else
  24.             cout << a << "x^2";
  25.     }
  26.     else if (a > 0)
  27.         if (a == 1)
  28.             cout << "x^2";
  29.         else
  30.             cout << a << "x^2";
  31.     if (b < 0) {
  32.         if (b == -1)
  33.             cout << "-x";
  34.         else
  35.             cout << b << "x";
  36.     }
  37.     else if (b > 0) {
  38.         if(a==0)
  39.             if(a==1)
  40.                 cout << "x";
  41.             else
  42.                 cout << b << "x";
  43.         else
  44.             if(a==1)
  45.                 cout << "+" << "x";
  46.             else
  47.                 cout << "+" << b << "x";
  48.     }
  49.     else;
  50.     if (c < 0)
  51.         cout << c;
  52.     else if (c > 0) {
  53.         if (b == 0 && a==0)
  54.             cout << c;
  55.         else
  56.             cout << "+" << c;  
  57.     }
  58.     else;
  59.     cout << endl;
  60.  
  61.     double result{};
  62.     result = a * x *x + b * x + c;
  63.     cout << "***********************" << endl;
  64.     cout << "f(" << x << ")=" << result<<endl;
  65.     cout << "***********************" << endl;
  66.  
  67.     system("pause");
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement