#13953: 第五資測為甚麼會錯


bbubble0906 (bbubble0906)


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
int ansA , ansB , a , b , c ;
double D;

while(cin >> a >> b >> c)
{
D = b*b-4*a*c;
if(D > 0)
{
ansA = (-b+sqrt(D))/2*a;
ansB = (-b-sqrt(D))/2*a;
cout <<"Two different roots x1=" <<ansA <<" , x2=" <<ansB <<endl;
}

else if(D == 0)
{
ansA = -b/2*a;
cout <<"Two same roots x=" <<ansA <<endl;
}

else cout<<"No real root" <<endl;
}
}

#13996: Re:第五資測為甚麼會錯


anandrewboy70900 (ShowTsai)


2*a要括號

(2*a)