解一元二次方程

时间:2021-09-24 00:01:46
<img src="http://img.blog.csdn.net/20141027224232390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGF5bmVzbHVv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" /><img src="http://img.blog.csdn.net/20141027224232390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGF5bmVzbHVv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
<!--StartFragment --><div>//  // Copyright (c) 2014软件技术1班  // All rights reserved.   // 作    者:A23罗燕芬    // 完成日期:2014年 10 月 27 日   // 版 本 号:v1.0   //   // 问题描述:求一元二次方程。ax²+bx+c=0(a≠0)  // 输入描述:三个数   // 程序输出:方程的解  //   </div>
 
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            double a, b, c, d, 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 (Math.Pow(b, 2) - 4 * a * c >= 0)            {                d = (-b + Math.Sqrt(b * b - 4 * a * c)) / 2 * a;                e = (-b - Math.Sqrt(b * b - 4 * a * c)) / 2 * a;                Console.WriteLine("方程ax*x+bx+c=0的两个解分别为{0}和{1}", d, e);                Console.Read();            }            else            {                Console.WriteLine("无解");                Console.Read();            }        }    }}
 
总结:我学到了 Math.Sqrt()是用来求平方根的,知道了if的用处。