using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
double a, b, c,x1,x2;
Console.WriteLine("输入三个数a、b、c");
a = Convert.ToDouble(Console.ReadLine());
b = Convert.ToDouble(Console.ReadLine());
c = Convert.ToDouble(Console.ReadLine());
x1 = (-b - Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
x2 = (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
if (b* b - 4 * a * c > 0)
Console.WriteLine("x1={0} ,x2={1} ", x1, x2);
else if (b * b - 4 * a * c < 0)
Console.WriteLine("错误,无解");
x1 = x2 = -b / (2 * a);
Console.WriteLine("x1={0} ,x2={1}", x1, x2);
Console.Read();
}
}
}
C#一元二次方程
最新推荐文章于 2022-09-09 14:42:42 发布