HQ-day3 C#语句实例②一元二次方程
Console.WriteLine("判断此方程是不是一元二次方程");
Console.WriteLine("ax*x+bx+c=0");
Console.WriteLine();
Console.Write("请输入a=");
double a = double.Parse(Console.ReadLine());
Console.Write("请输入b=");
double b = double.Parse(Console.ReadLine());
Console.Write("请输入c=");
double c = double.Parse(Console.ReadLine());
double d = b * b - 4 * a * c;
if (a == 0)
{
Console.WriteLine("此方程不是一元二次方程");
}
else
{
Console.WriteLine("此方程是一元二次方程");
}
if (d >= 0)
{
double x1 = (-b + Math.Sqrt(d)) / (2 * a);
double x2 = (-b - Math.Sqrt(d)) / (2 * a);
if (d > 0)
{
Console.WriteLine("此方程有两个不相同的实根");
Console.WriteLine("x1="+x1 + "x2="+x2);
}
else
{
Console.WriteLine("此方程有两个相同的实根");
Console.WriteLine("x1=x2="+x1);
}
}
else if (d < 0)
{
Console.WriteLine("方程无实根");
}