During compilation, the code gives correct results but while submission,it shows all test cases failed.
My code:
#include
#include
using namespace std;
int main() {
float a, b, c, x1, x2, discriminant, realPart, imaginaryPart;
cin >> a >> b >> c;
discriminant = b*b - 4*a*c;
if (discriminant > 0) {
x1 = (-b + sqrt(discriminant)) / (2*a);
x2 = (-b - sqrt(discriminant)) / (2*a);
cout << "Real and distinct" << endl;
cout << x1 <<" "<< x2 << endl;
}
else if (discriminant == 0) {
cout << "Real and equal" << endl;
x1 = -b/(2*a);
cout << x1 << " "<< x1 << endl;
}
else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
cout << "Imaginary" << endl;
cout << realPart << "+" << imaginaryPart << "i" << " "<<realPart << "-" << imaginaryPart << "i" << endl;
}
return 0;
}