<img src="https://img-blog.csdn.net/20141028073623217?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR1hDQm9r/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />// Copyright (c)
2014软件技术1班
// All rights reserved.
// 作 者:A18
// 完成日期:2014年 10 月 28 日
// 版 本 号:v1.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
double a, b, c;
Console.Write("a=");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("b=");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("c=");
c = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(a + "x^2+" + b + "x+" + c + "=0");
double d = b * b - 4 * a * c;
double x1, x2;
if (d > 0)
{
x1 = (-b - Math.Sqrt(d)) / 2.0 / a;
x2 = (-b + Math.Sqrt(d)) / 2.0 / a;
Console.WriteLine("方程有两个不同的实根\nx1={0}\nx2={1}", x1, x2);
}
else if (d == 0)
{
x1 = x2 = (-b) / 2.0 / a;
Console.WriteLine("方程有两个相同的实根\nx1={0}\nx2={1}", x1, x2);
}
else
{
double i = Math.Sqrt(-d) / 2.0/a;
x1 = x2 = -b / 2.0 / a;
Console.WriteLine("方程有两个复根\nx1={0}-{1}i\nx2={2}+{3}i", x1, i, x2, i);
Console.Read();
}
}
}
}