为什么输入1,-2,1会显示索引<从零开始>必须大于零或等于零,必须小于参数列表的大小

/*实验2 求解一元二次方程
实验要求:输入一元二次方程的三个系数a,b,c,求 方程的解。
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace equation
{
class Program
{
static void Main(string[] args)
{
double a, b, c, delta, x1, x2;
Console.Write("请输入系数a:");
String s = Console.ReadLine();
a = double.Parse(s);
Console.Write("请输入系数b:");
s= Console.ReadLine();
b = double.Parse(s);
Console.Write("请输入系数c:");
s= Console.ReadLine();
c = double.Parse(s);
delta = b * b - 4 * a * c;
if(a==0&&b==0)
{
Console.WriteLine("该方程无解");
}
else if(a==0&&b!=0)
{
x1 = x2 = -c / b;
Console.WriteLine("有一个实根:{0}", x1);
}

else if(delta>0)
{
x1=(-b+delta)/(2*a);
x2=(-b-delta)/(2*a);
Console.WriteLine("有两个不相等的实根:{0},{1}",x1,x2);
}
else if(delta==0)
{
x1 = x2 = -b / (2 * a);
Console.WriteLine("有两个相等的实根:{0},{1}",x1);
}
else if(delta<0)
{
x1 = (-b / 2 * a) + delta / (2 * a);
x2 = (-b / 2 * a) - delta / (2 * a);
Console.WriteLine("有两个共轭复根:{0},{1}", x1, x2);
}
}
}
}

Console.WriteLine("有两个相等的实根:{0},{1}",x1);这里出问题了
改为Console.WriteLine("有两个相等的实根:{0}",x1);
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜