编程求一元二次方程。ax²+bx+c=0(a≠0)

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

namespace ConsoleApplication3
{
    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));
                Console.ReadKey();

            }
            {
                Console.WriteLine("无解!");
                Console.ReadKey();
            }
        }
    }
}


总结:让我学会了如何编程求一元二次方程;感觉到了互帮互助的集体感


版权声明:本文为nuoyan007原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。