using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) {//判断一个方程是不是一个一元二次方程,并判断解得情况 Console.WriteLine("a*x*x+b*x+c=0"); 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.ToString() + "x1=" + x2.ToString()); } else if (D == 0) { Console.WriteLine("方程式有两个相等的实根"); Console.WriteLine("x1=x2=" + x1.ToString()); } } else if (D < 0) { Console.WriteLine("方程没有实根"); } Console.ReadLine(); } } } }
2015.09.01今天预习做得习题!!