求一元二次方程

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace yiyuan  
  8. {  
  9.     class Program  
  10.     {  
  11.         static void Main(string[] args)  
  12.         {  
  13.             double x1 =0 , x2 = 0;   
  14.             double a, b, c, dt;  
  15.             Console.Title = ("一元二次方程");  
  16.             Console.WriteLine("ax^2+bx=0");  
  17.             Console.WriteLine("请输入a的值:");  
  18.             a = Convert.ToInt32(Console.ReadLine());  
  19.             Console.WriteLine("请输入b的值:");  
  20.             b = Convert.ToInt32(Console.ReadLine());  
  21.             Console.WriteLine("请输入c的值:");  
  22.             c = Convert.ToInt32(Console.ReadLine());  
  23.             dt = b * b - 4 * a * c;                       
  24.             if (dt > 0)                    
  25.             {  
  26.                 x1 = (-b + Math.Sqrt(dt)) / 2.0 * a;    
  27.                 x2 = (-b - Math.Sqrt(dt)) / 2.0 * a;  
  28.                 Console.WriteLine("有两个解");  
  29.                 Console.WriteLine("x1={0}\nx2={1}", x1, x2);  
  30.             }  
  31.             else if (dt == 0)  
  32.             {  
  33.                 x1 = x2 = -b / (2 * a);      //一元二次方程公式  
  34.                 Console.WriteLine("x1=x2={0}", x1);  
  35.                 Console.WriteLine("有一个解");  
  36.             }  
  37.   
  38.             else  
  39.             {  
  40.                 Console.WriteLine("无解");  
  41.   
  42.             }  
  43.             
  44.   
  45.             Console.Read();  
  46.   
  47.   
  48.   
  49.         }  
  50.     }  
  51. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值