Advertisement
rootuss

rownanie kwadratowe

Oct 24th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     double a, b, c, delta;
  10.  
  11.     cout<<endl;
  12.     cout<<"STABILNY ALGORYTM  OBLICZAJACY ROWNANIE KWADRATOWE" <<endl<<endl<<endl;
  13.  
  14.     cout << "Podaj a, b, c:" << endl;
  15.     cout<<"a= ";
  16.     cin>>a;
  17.     cout<<"b= ";
  18.     cin>>b;
  19.     cout<<"c= ";
  20.     cin>>c;
  21.     delta=pow(b,2)-4*a*c;
  22.     cout<<endl;
  23.  
  24.     if (a==0)
  25.         {
  26.             cout<<"To nie jest rownanie kwadratowe!!!" <<endl;
  27.         }
  28.     else if (delta<0)
  29.         {
  30.             cout<<"Rownanie nie ma pierwiastkow" <<endl;
  31.         }
  32.     else if (delta==0)
  33.         {
  34.             double x= -b/(2*a);
  35.             cout<<"Rozwiazanie to: "<<x;
  36.             cout<<endl;
  37.         }
  38.     else
  39.         {
  40.                 double pom=c/a;
  41.  
  42.                 if(b>0)
  43.                     {
  44.                         double x1=(-b-sqrt(delta))/(2*a);
  45.                         double x2=pom/x1;
  46.  
  47.                         cout<<"Rozwiazania to: "<<x1<<" oraz "<<x2<<endl;
  48.                         cout<<endl;
  49.                     }
  50.                 else
  51.                     {
  52.                         double x2=(-b+sqrt(delta))/(2*a);
  53.                         double x1=pom/x2;
  54.                         cout<<"Rozwiazania to: "<<x1<<" oraz "<<x2<<endl;
  55.                         cout<<endl;
  56.                     }
  57.         }
  58.     system("pause");
  59.     return 0;
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement