using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { //out 变成输出参数,通过out public double jieguo(double a, double b, double c, out double x1, out double x2) { double de = Math.Sqrt(b * b - 4 * a * c); x1 = 0; x2 = 0; if (a == 0) { return 3; } else { if (de > 0) { x1 = (-b + de) / 2 * a; x2 = (-b - de) / 2 * a; return 2; } else if (de == 0) { x1 = (-b + de) / 2 * a; x2 = x1; return 1; } else { return 0; } }} static void Main(string[] args) { 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 x1; double x2; double f = new Program().jieguo(a, b, c, out x1, out x2); Console.ReadLine(); if (f == 2) { Console.WriteLine("此方程有两个不相等实根"+x1 +" "+x2 ); } if (f == 1) { Console.WriteLine("此方程有两个相等实根"+x1 +" "+x2); } if (f == 0) { Console.WriteLine("此方程没有 实根"); } if (f == 3) { Console.WriteLine("此方程不是一元二次方程"); } Console.ReadLine(); } } }