- 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 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();
- }
- }
- }
求一元二次方程
最新推荐文章于 2022-01-17 19:30:55 发布