解一元二次方程

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
double a, b, c;//设置变量
Console.WriteLine(“请输入a、b、c:”);
a = Convert.ToDouble(Console.ReadLine());//控制台输出数据给a b c
b = Convert.ToDouble(Console.ReadLine());
c = Convert.ToDouble(Console.ReadLine());
if (Math.Pow(b, 2) - 4 * a * c >= 0)//按照求根公式判断是否有解
{
Console.WriteLine("x1 = " + (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a));//满足条件第一个解x1
Console.WriteLine("x2 = " + (-b - Math.Sqrt(b * b - 4 * a * c)) / (2 * a));//满足条件第二个解x2
}
else
{
Console.WriteLine(“无解”);//不满足条件则无解
}
Console.Read();//此处用于输出定格
}
}
}

猜你喜欢

转载自blog.csdn.net/ithui520/article/details/88130474
今日推荐