歷經千辛萬苦寫出的程式
卻無情遭NA
*** 第 5 點 (20%):WA (line:1)
您的答案為: Two different roots x1=- ...略
正確答案為: Two same roots x=-1
WHY?
以下是我的程式碼:
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
double an1,an2;
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) cout<<"Two same roots x="<<an1<<endl;
else if(an1!=an2) cout<<"Two different roots x1="<<an1<<" , x2="<<an2<<endl;
}
return EXIT_SUCCESS;
}