码迷,mamicode.com
首页 > 其他好文 > 详细

利用if else 判断方程有几个根

时间:2015-03-28 15:40:03      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

static void Main(string[] args)
        {
             Console.ForegroundColor = ConsoleColor.Green;
            Console.Clear();
            while (true)
            {

                Console.WriteLine("求方程式ax²+bx=c=0的根的情况");
                double a, b, c, d; string e;
                Console.WriteLine("请输入a:");
                a = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("请输入b:");
                b = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("请输入c:");
                c = Convert.ToDouble(Console.ReadLine());
                if (a > 0||a<0)
                {
                    Console.WriteLine("方程为一元二次方程");

                    d = b * b - 4 * a * c;
                    Console.WriteLine("形成的德尔塔为" + d);
                    if (d > 0)
                    {
                        Console.WriteLine("方程有两个根");
                    }
                    else if (d == 0)
                    {
                        Console.WriteLine("方程有一个根");
                    }
                    else
                    {
                        Console.WriteLine("方程无解");

                    }

                }
                else
                {
                    Console.WriteLine("方程不是一元二次方程");
                }

                Console.ReadLine();


            }
        }
    }

利用if else 判断方程有几个根

标签:

原文地址:http://www.cnblogs.com/lk-kk/p/4374281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!