// Copyright (c) 2014软件技术1班
// All rights reserved.
// 作 者:A28余锦滔
// 完成日期:2014年 10 月 26 日
// 版 本 号:v1.0
//
// 问题描述:创建一个程序来解一元二次方程。该程序提示用户输入任意实数,然后得出无解。
// 输入描述:任意三个实数,
// 程序输出:无解
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
double a, b, c;
Console.WriteLine("请输入a'b'c:");
a = Convert.ToDouble(Console.ReadLine());
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));
Console.WriteLine("x2=" + (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a));
}
else
{
Console.WriteLine("无解!");
Console.Read();
}
}
}
}
输出结果