Advertisement
justkiddin

Phuong trinh bac 2

Dec 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. //@___justkiddin
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. float a,b,c;
  7. float x1,x2;
  8.  
  9. int giaiPT(){
  10.     float delta = b*b - 4*a*c;
  11.     if(delta < 0){
  12.         x1 = x2 = 0.0;
  13.         return 0;
  14.     }
  15.     else if(delta == 0){
  16.         x1 = x2 = -b / (2*a);
  17.         return 1;
  18.     }
  19.     else{
  20.         delta = sqrt(delta);
  21.         x1 = (-b + delta) / (2*a);
  22.         x2 = (-b - delta) / (2*a);
  23.         return 2;
  24.     }
  25. }
  26.  
  27. int main(){
  28.     do{
  29.         cout << "Nhap a (a!=0): ";  cin >> a;
  30.         cout << "Nhap b: "; cin >> b;
  31.         cout << "Nhap c: "; cin >> c;
  32.     }
  33.     while(a == 0);
  34.  
  35.     int numNo = giaiPT();
  36.     if(numNo ==0 )
  37.         cout<<"Phuong trinh da cho vo nghiem";
  38.     else
  39.         if(numNo==1)
  40.             cout << fixed << setprecision(2) << "Phuong trinh da cho co nghiem kep x = " << x1;
  41.         else{
  42.             cout << "Phuong trinh da cho co hai nghiem phan biet"<<endl;
  43.             cout << "x1 = " << x1 << endl;
  44.             cout << "x2 = " << x2 << endl;
  45.         }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement