略做修改之後
結果還是NA
WHYWHY?
*** 第 5 點 (20%):WA (line:1)
您的答案為: Two same roots x=-4
正確答案為: Two same roots x=-1
程式碼:
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
double an1,an2;
long long double a,b,c;
while(cin>>a>>b>>c){
an1 = (-b + sqrt( b * b - 4 * a * c)) / 2 * a;
an2 = (-b - sqrt( b * b - 4 * a * c)) / 2 * a;
if((b * b - 4 * a * c)<0) cout<<"No real root"<<endl;
else if(an1==an2&&(b * b - 4 * a * c)==0) cout<<"Two same roots x="<<an1<<endl;
else if(an1!=an2&&(b * b - 4 * a * c)>0) cout<<"Two different roots x1="<<an1<<" , x2="<<an2<<endl;
}
return EXIT_SUCCESS;
}