2015
04-13

# A pupil’s problem

Wei wei is a pupil. He is tired of calculating the quadratic equation. He wants you to help him to get the result of the quadratic equation. The quadratic equation’ format is as follows: ax^2+bx+c=0.

The first line contains a single positive integer N, indicating the number of datasets. The next N lines are n datasets. Every line contains three integers indicating integer numbers a,b,c (a≠0).

The first line contains a single positive integer N, indicating the number of datasets. The next N lines are n datasets. Every line contains three integers indicating integer numbers a,b,c (a≠0).

3
1 2 1
1 2 3
1 -9 6

-1.00
NO
0.73 8.27

ps:解二次方程，wrong了一次，x1和x2木有判断大小！！！

(1)若b^2-4ac<0，无实数根，有两个复数根：x1=[-b+i√(4ac-b^2)]/(2a) ， x2=[-b-i√(4ac-b^2)]/(2a)；
(2)若b^2-4ac=0，有两个相等实根： x1=x2=-b/(2a)；
(3)若b^2-4ac>0，有两个不等实根： x1=[-b+√(b^2-4ac)]/(2a) ，x2=[-b-√(b^2-4ac)]/(2a) 。

#include<stdio.h>
#include<math.h>
int main()
{
int t;
int a,b,c;
double x1,x2,x,temp;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&a,&b,&c);
x=b*b-4*a*c;
if(x<0)
printf("NO\n");
else if(x==0)
{
x1=-1.0*b/(2*a);
printf("%.2f\n",x1);
}
else if(x>0)
{
x1=(-1.0*b-sqrt(x))/(2*a);
x2=(-1.0*b+sqrt(x))/(2*a);
if(x1>x2)//
{
temp=x1;x1=x2;x2=temp;
}
printf("%.2f %.2f\n",x1,x2);
}
}
return 0;
}