以下是程式碼
#include <iostream>
using namespace std;
int main(){
do{
double a, b, c;
double x, y;
cin >> a >> b >> c;
x = ((-b) + sqrt((b*b) - (4 * a*c))) / 2 * a;
y = ((-b) - sqrt((b*b) - (4 * a*c))) / 2 * a;
if (x != y)
cout << "Two different roots x1 = " << x << ", x2 = " << y << endl;
else if (x == y)
cout << "Two same roots x = " << x << endl;
else
cout << "No real root" << endl;
} while (1);
return 0;
}
答案都對阿~但為啥不過呢?