- //
- // Copyright (c) 2014软件技术1班
- // All rights reserved.
- // 作 者:A30 黄勇华
- // 完成日期:2014年 10 月 27 日
- // 版 本 号:v1.0
- //
- // 问题描述: 编程求一元二次方程的根
- // 输入描述:输入式子中的三个变量b,b,c,
- // 程序输出:输出式子的两个根的值
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
-
- namespace 一元二次方程计算
- {
- class Program
- {
- static void Main(string[] args)
- {
- String a;
- String b;
- String c;
- double x1;
- double x2;
-
-
- Console.WriteLine("请输入a,b,c的值:");
- a = Console.ReadLine();
- b = Console.ReadLine();
- c = Console.ReadLine();
- double a1 = double.Parse(a);
- double b1 = double.Parse(b);
- double c1 = double.Parse(c);
-
-
- if (b1 * b1 - 4 * a1 * c1 > 0)
- {
- x1 = (-b1 - Math.Sqrt(b1 * b1 - 4 * a1 * c1)) / (2 * a1);
- x2 = (-b1 + Math.Sqrt(b1 * b1 - 4 * a1 * c1)) / (2 * a1);
- Console.WriteLine("x1与X2分别等于:" + x1 + x2);
- Console.Read();
- }
-
-
-
-
- else if (b1 * b1 - 4 * a1 * c1 < 0)
- {
- Console.WriteLine("错误,无解");
- Console.Read();
- }
- else
- {
- x1 = x2 = -b1 / (2 * a1);
- Console.WriteLine("两根相等,x1=x2=" + x1);
- Console.Read();
- }
- }
- }
- }
- 输出:
-
- 总结:
- 1.在这次作业中稳固了前几次所学内容
- 2.学会了在一次编辑中对几个变量的输入与运算
- 3.强化了编程意识
- 4.更深刻了解编程环境
一元二次求根方程
最新推荐文章于 2020-10-03 10:54:15 发布