求一元二次方程

#include<stdio.h>
#include<math.h>
int main()
{
	double a = 0;
	double b = 0;
	double c = 0;
	scanf("%lf %lf %lf", &a, &b, &c);
	double x1 = 0;
	double x2 = 0;
	double B = 0;
	double C = 0;
	B = (b * b) - (4 * a * c);
	C = sqrt(B);
	x1 = (-b + C) / (2 * a);
	x2 = (-b - C) / (2 * a);
	if (a!=0)
	{
		if (B>=0)
		{
			if (x1 == x2)
			{
				printf("x1=x2=%.5lf", x1);
			}
			else if (x1 != x2)
			{
				if (x1 > x2)
				{
					printf("x1=%.5lf;x2=%.5lf", x2, x1);
				}
				else if (x1 < x2)
				{
					printf("x1=%.5lf;x2=%.5lf", x1, x2);
				}
			}
		}
		if (B<0)

		{
			printf("No answer!");
		}
	}
	return 0;
}


运行结果:

习题专题-求一元二次方程_#求一元二次方程