这个题目的纯虚根问题搞的头大,其实没意思。
#include <stdio.h>
#include <math.h>
int main(void)
{
double a, b, c;
scanf("%lf%lf%lf", &a, &b, &c);
double delta = b * b - 4 * a * c;
if (a == 0 && b == 0 && c == 0)
{
printf("Zero Equation
");
}
else if (a == 0 && b == 0 && c != 0)
{
printf("Not An Equation
");
}
else if (a == 0 && b != 0)
{
printf("%.2f
", -c / b);
}
else if (a != 0)
{
if (delta == 0)
{
printf("%.2f
", -b / 2 / a);
}
else if (delta > 0)
{
printf("%.2f
", (-b + sqrt(delta)) / (2 * a));
}
else
{
if (b == 0)
{
printf("%.2f+%.2fi
%.2f-%.2fi
", 0 / 2 / a, sqrt(-delta) / 2 / a, 0 / 2 / a, sqrt(-delta) / 2 / a);
}
else
{
printf("%.2f+%.2fi
%.2f-%.2fi
", -b / 2 / a, sqrt(-delta) / 2 / a, -b / 2 / a, sqrt(-delta) / 2 / a);
}
//printf("%.2f+%.2fi
%.2f-%.2fi
", (b == 0 ? b : -b) / 2 / a, sqrt(-delta) / 2 / a, (b == 0 ? b : -b) / 2 / a, sqrt(-delta) / 2 / a);
}
}
return 0;
}