Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@___justkiddin
- #include <bits/stdc++.h>
- using namespace std;
- float a,b,c;
- float x1,x2;
- int giaiPT(){
- float delta = b*b - 4*a*c;
- if(delta < 0){
- x1 = x2 = 0.0;
- return 0;
- }
- else if(delta == 0){
- x1 = x2 = -b / (2*a);
- return 1;
- }
- else{
- delta = sqrt(delta);
- x1 = (-b + delta) / (2*a);
- x2 = (-b - delta) / (2*a);
- return 2;
- }
- }
- int main(){
- do{
- cout << "Nhap a (a!=0): "; cin >> a;
- cout << "Nhap b: "; cin >> b;
- cout << "Nhap c: "; cin >> c;
- }
- while(a == 0);
- int numNo = giaiPT();
- if(numNo ==0 )
- cout<<"Phuong trinh da cho vo nghiem";
- else
- if(numNo==1)
- cout << fixed << setprecision(2) << "Phuong trinh da cho co nghiem kep x = " << x1;
- else{
- cout << "Phuong trinh da cho co hai nghiem phan biet"<<endl;
- cout << "x1 = " << x1 << endl;
- cout << "x2 = " << x2 << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement