求一元二次方程ax²+bx+c=0

来源:互联网 发布:阿里云哪个节点好 编辑:程序博客网 时间:2024/05/21 22:25
// Copyright (c) 2014软件技术1班      // All rights reserved.       // 作    者:A24龙俊全   // 完成日期:2014年 10 月 25 日       // 版 本 号:v1.0       //       // 问题描述:创建一个程序来求一元二次方程ax²+bx+c=0的解。      // 输入描述:三个数      // 程序输出:方程的解 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("方程ax2+bx+c=0的两个解分别为{0}和{1}", d, e);                Console.Read();            }            else            {                Console.WriteLine("无解");                Console.Read();            }        }    }}


总结:

经过这次作业我学习了如何使用if语句和编写求简单方程的程序

0 0