Kassiow

RÓWNANIE KWADRATOWE

Oct 29th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. void liniowe(float a, float b){
  5.   if(a==0)
  6.     if(b==0)
  7.       cout<<"Rownaie tozsamosciowe"<<endl;
  8.     else
  9.       cout<<"Rownanie sprzeczne"<<endl;
  10.   else{
  11.     float x;
  12.     x=-b/a;
  13.     cout<<"x = "<<x;
  14.   }
  15. }
  16. int main(void){
  17.   float a, b, c;
  18.   cout<<"a = ";
  19.   cin>>a;
  20.   cout<<"b = ";
  21.   cin>>b;
  22.   cout<<"c = ";
  23.   cin>>c;
  24.   if(a==0)
  25.     liniowe(b, c);
  26.   else{
  27.     float delta;
  28.     delta=b*b-4*a*c;
  29.     if(delta<0)
  30.       cout<<"Brak rozwiazan"<<endl;
  31.     else
  32.     if(delta==0){
  33.       float x;
  34.       x=-b/(2*a);
  35.       cout<<"Jedno podwojne rozwiazanie x = "<<x<<endl;
  36.     } else{
  37.       float x1, x2;
  38.       x1=(-b+sqrt(delta))/(2*a);
  39.       x2=(-b-sqrt(delta))/(2*a);
  40.       cout<<"x1 = "<<x1<<endl;
  41.       cout<<"x2 = "<<x2<<endl;
  42.     }
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment