#include <math.h>
#include<stdio.h>
int main()
{
float a = 0.0;
float b = 0.0;
float c = 0.0;
while( scanf("%f %f %f", &a, &b, &c) == 3)//多组输入
{
float x1 = 0.0;
float x2 = 0.0;
if(a == 0)
{
printf("Not quadratic equation\n");
}
else
{
float der = (b*b) - (4*a*c);//计算 der 的值
if(der == 0)
{
x1 = (-b) / (2*a);
x2 = x1;
if(x1 == (-0.0))
{
x1 = 0.00;
x2 = 0.00;
}
printf("x1=x2=%0.2f\n", x1);
}
else if(der > 0)
{
x1 = (-b - sqrt(der)) / (2*a);
x2 = (-b + sqrt(der)) / (2*a);
printf("x1=%0.2f;x2=%0.2f\n", x1, x2);
}
else
{
x1 = (-b) / (2*a);
x2= (-b) / (2*a);
printf("x1=%0.2f-%0.2fi;x2=%0.2f+%0.2fi\n", x1, sqrt(-der) / (2*a), x2, sqrt(-der) / (2*a));//复数没办法直接从计算机输出,所以需要用printf来凑出复数的实部+虚部的形式
}
}
}
return 0;
}

京公网安备 11010502036488号