Bài toán. Nhập a, b, c nguyên. Giải và biện luận phương trình ax2 + bx + c = 0. Ví dụ:
PTBH.INP |
PTBH.OUT |
1 -3 2 |
1 2 |
Code tham khảo:
#include<iostream>
#include <math.h>
using namespace std;
int main() {
freopen("PTBH.INP","r",stdin);
freopen("PTBH.OUT","w",stdout);
int a, b, c, d;
cin >> a >> b >> c;
d = b*b - 4*a*c;
if (d < 0) cout << "Vo nghiem";
else if (d == 0) {
double x = -b / (2*a);
cout << x;
}
else {
double x1 = (-b - sqrt(d))/(2*a);
double x2 = (-b + sqrt(d))/(2*a);
cout << x1 << " " << x2;
}
return 0;
}