Индекс находится вне границы массива! C#
Ошибку выдает в 42 строке(
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
float[] Y = new float[100];
float A, B, h;
int i;
A = float.Parse(textBox1.Text);
B = float.Parse(textBox2.Text);
h = float.Parse(textBox3.Text);
i = 0;
for (float Z = A; Z <= B; Z += h) {
float X = (float)Math.Pow(Z, (1.0 / 3.0));
i++;
if (X > 1)
{
Y[i] = (float)Math.Log(1 + (float)Math.Exp(2 * X));
}
else
{
Y[i] = (float)Math.Atan(X / Math.Pow((1 + Math.Pow(X, 2)), 1 / 2));
}
int index = dataGridView1.Rows.Add();
dataGridView1.Rows[index].Cells[0].Value = Z.ToString("0.0");
dataGridView1.Rows[index].Cells[1].Value = X.ToString("0.000");
dataGridView1.Rows[index].Cells[2].Value = Y[i].ToString("0.000");
}
}
}
}