Advertisement
Matrxi999

Untitled

Apr 16th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int a, b, c, x1, x2, delta; //inicjowanie intów
  9.     cout << "Podaj współczynnik a:" << endl;
  10.     cin >> a;
  11.     cout << "Podaj współczynnik b:" << endl;
  12.     cin >> b;
  13.     cout << "Podaj współczynnik c:" << endl;
  14.     cin >> c;
  15.  
  16.     if (a==0)
  17.     {
  18.         x1 = -c/b;
  19.         cout << "Wynik to x1:" << endl;
  20.         cout << x1 << endl;
  21.     }
  22.     else
  23.     {
  24.         delta = pow(b,2)-4*a*c;
  25.         if (delta>0)
  26.         {
  27.             x1 = (-b-pow(delta,1/2))/(2*a);
  28.             x2 = (-b+pow(delta,1/2))/(2*a);
  29.             cout << "Wynik to x1:" << endl << x1 << endl;
  30.             cout << "Wynik to x2:" << endl << x2 << endl;
  31.         }
  32.         else if (delta==0)
  33.         {
  34.             x1 = -b/2*a;
  35.             cout << "Wynik to x1:" << endl << x1 << endl;
  36.         }
  37.         else if (delta<0)
  38.         {
  39.             cout << "Brak rozwiązań" << endl << endl;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement