2 câu trả lời
program tin_hoc;
uses crt;
var a,b,c, : real;
x1,x2: longint;
begin
readln( a,b,c);
x1 :=(-b+sqrt( b*b-4*a*c))/(2*a);
x2 := (-b-sqrt( b*b-4*a*c))/(2*a);
writeln( 'nghiem x1 la',x1);
write (' nghiem x2 la', x2);
Readln
End.
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
int main()
{
float a, b, c, delta, x1, x2;
cout << "a";
cin >> a;
cout << "b";
cin >> b;
cout << "c";
cin >> c;
if(a == 0) {
if(b == 0) {
if (c == 0) {
cout << "Phuong trinh vo so nghiem" << endl;
} else {
cout << "Phuong trinh vo nghiem" << endl;
}
} else {
cout << "Phuong trinh co nghiem duy nhat: " << -c/b << endl;
}
} else {
delta = b*b - 4*a*c;
if(delta > 0) {
x1 = (-b+sqrt(delta))/(2*a);
x2 = (-b-sqrt(delta))/(2*a);
cout << "Nghiem thu nhat x1 = " << x1 << endl;
cout << "Nghiem thu hai x2 = " << x2 << endl;
} else if ( delta == 0) {
cout << "Phuong trinh co nghiem kep: x1 = x2 = " << -b/2*a << endl;
} else {
cout << "Phuong trinh vo nghiem" << endl;
}
}
return 0;
}