求一元二次方程
2014-10-27 11:23
375 查看
// Copyright (c) 2014软件技术2班 // All rights reserved. // 作 者:B14 // 完成日期:2014年 10 月 24 日 // 版 本 号:v1.0 // 问题描述:创建一个程序求一元二次方程 //输入描述:任意输入 a b c 值,根据公式计算x1,x2并输出 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace yiyuan { class Program { static void Main(string[] args) { double x1 =0 , x2 = 0; //定义double类型,名称x1.x2初始化为0 double a, b, c, dt; Console.Title = ("求一元二次方程"); Console.WriteLine("ax^2+bx=0"); Console.WriteLine("请输入a的值:"); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入b的值:"); b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入c的值:"); c = Convert.ToInt32(Console.ReadLine()); dt = b * b - 4 * a * c; //Δ的公式 if (dt > 0) //判断Δ { x1 = (-b + Math.Sqrt(dt)) / 2.0 * a; //一元二次方程公式 x2 = (-b - Math.Sqrt(dt)) / 2.0 * a; Console.WriteLine("有两个实数根"); Console.WriteLine("x1={0}\nx2={1}", x1, x2); } else if (dt == 0) { x1 = x2 = -b / (2 * a); //一元二次方程公式 Console.WriteLine("x1=x2={0}", x1); Console.WriteLine("仅一个解"); } else { Console.WriteLine("无解"); } Console.Read(); } } }
输出:
总结:通过这个,我比较明白了变量类型的运用。
相关文章推荐
- 分支-18. 求一元二次方程的根(20)
- Openjudge-计算概论(A)-求一元二次方程的根
- 求一元二次方程求根公式与韦达定理.
- 分支-18 求一元二次方程的根(20)
- 求一元二次方程的根
- 用类方法求解一元二次实系数方程
- 1028: 例题3-5 求一元二次方程的根
- 求一元二次方程的根
- 百练_2707 求一元二次方程的根
- 我的第十六个C++上机报告(求一元二次方程的根)
- C语言程序 求一元二次方程的解
- 第九周 求一元二次方程的解
- 例题(8.3) 求一元二次方程的根 (1051)
- 求一元二次方程
- C#一元二次方程的程序;
- 算法:求一元二次方程ax^2 + bx + c = 0的根
- 求一元二次方程ax^2+bx+c=0的根
- if语句(判断结婚条件和一元二次方程)
- 8.求一元二次方程的根(未经评测)
- 什么是一元一次方程和一元二次方程