private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtA.Text == "" && txtB.Text == "")
            {
                if (questions.SelectedIndex == 0)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }


                    for (int i = 0; i < 10; i++)
                    {
                        if (ques.bisection1(i) < 0 && ques.bisection1(i + 1) > 0)
                        {
                            a = i;
                            b = i + 1;
                            break;
                        }
                    }

                    c     = (a + b) / 2;
                    error = Math.Abs((b - a) / 2);



                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), string.Format("{0:0.000}", a), string.Format("{0:0.000}", b), string.Format("{0:0.000}", (ques.bisection1(a))), string.Format("{0:0.000}", (ques.bisection1(b))), string.Format("{0:0.000}", c), string.Format("{0:0.000}", ques.bisection1(c)), string.Format("{0:0.000}", error));

                            if (ques.bisection1(a) * ques.bisection1(c) < 0)
                            {
                                b     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                            else
                            {
                                a     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (questions.SelectedIndex == 1)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        if (ques.bisection2(i) < 0 && ques.bisection2(i + 1) > 0)
                        {
                            a = i;
                            b = i + 1;
                            break;
                        }
                    }
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }


                    c     = (a + b) / 2;
                    error = Math.Abs((b - a) / 2);



                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), string.Format("{0:0.000}", a), string.Format("{0:0.000}", b), string.Format("{0:0.000}", (ques.bisection2(a))), string.Format("{0:0.000}", (ques.bisection2(b))), string.Format("{0:0.000}", c), string.Format("{0:0.000}", ques.bisection2(c)), string.Format("{0:0.000}", error));


                            if (ques.bisection2(a) * ques.bisection2(c) < 0)
                            {
                                b     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                            else
                            {
                                a     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (questions.SelectedIndex == 2)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }

                    for (int i = 0; i < 10; i++)
                    {
                        if (ques.bisection3(i) < 0 && ques.bisection3(i + 1) > 0)
                        {
                            a = i;
                            b = i + 1;
                            break;
                        }
                    }

                    c     = (a + b) / 2;
                    error = Math.Abs((b - a) / 2);



                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), string.Format("{0:0.000}", a), string.Format("{0:0.000}", b), string.Format("{0:0.000}", (ques.bisection3(a))), string.Format("{0:0.000}", (ques.bisection3(b))), string.Format("{0:0.000}", c), string.Format("{0:0.000}", ques.bisection3(c)), string.Format("{0:0.000}", error));


                            if (ques.bisection3(a) * ques.bisection3(c) < 0)
                            {
                                b     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                            else
                            {
                                a     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                a = Convert.ToDouble(txtA.Text);
                b = Convert.ToDouble(txtB.Text);
                if (questions.SelectedIndex == 0)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }



                    c     = (a + b) / 2;
                    error = Math.Abs((b - a) / 2);



                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), a.ToString(), b.ToString(), ques.bisection1(a).ToString(), ques.bisection1(b).ToString(), c.ToString(), ques.bisection1(c).ToString(), error.ToString());

                            if (ques.bisection1(a) * ques.bisection1(c) < 0)
                            {
                                b     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                            else
                            {
                                a     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (questions.SelectedIndex == 1)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }


                    c     = (a + b) / 2;
                    error = Math.Abs((b - a) / 2);


                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), a.ToString(), b.ToString(), ques.bisection2(a).ToString(), ques.bisection2(b).ToString(), c.ToString(), ques.bisection2(c).ToString(), error.ToString());

                            if (ques.bisection2(a) * ques.bisection2(c) < 0)
                            {
                                b     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                            else
                            {
                                a     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (questions.SelectedIndex == 2)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }



                    c     = (a + b) / 2;
                    error = Math.Abs((b - a) / 2);


                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), a.ToString(), b.ToString(), ques.bisection3(a).ToString(), ques.bisection3(b).ToString(), c.ToString(), ques.bisection3(c).ToString(), error.ToString());

                            if (ques.bisection3(a) * ques.bisection3(c) < 0)
                            {
                                b     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                            else
                            {
                                a     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtA.Text == "" && txtB.Text == "")
            {
                if (questions.SelectedIndex == 0)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        if (regular1(i) < 0 && regular1(i + 1) > 0)
                        {
                            a = i;
                            b = i + 1;
                            break;
                        }
                    }

                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }
                    MessageBox.Show(a.ToString());
                    MessageBox.Show(b.ToString());

                    ctemp = Convert.ToDouble(string.Format("{0:0.000}", ((a * ques.regular1(b) - b * ques.regular1(a)) / (ques.regular1(b) - ques.regular1(a)))));

                    error = Math.Abs(ctemp);

                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), string.Format("{0:0.000}", a), string.Format("{0:0.000}", b), string.Format("{0:0.000}", ques.regular1(a)), string.Format("{0:0.000}", ques.regular1(b)), ctemp.ToString(), string.Format("{0:0.000}", ques.regular1(ctemp)), string.Format("{0:0.000}", error));

                            if (ques.regular1(a) * ques.regular1(c) < 0)
                            {
                                b = ctemp;
                                c = Convert.ToDouble(string.Format("{0:0.000}", (a * ques.regular1(b) - ctemp * ques.regular1(a)) / (ques.regular1(b) - ques.regular1(a))));

                                error = Convert.ToDouble(string.Format("{0:0.000}", Math.Abs(c - ctemp)));
                                ctemp = c;
                            }
                            else
                            {
                                a = ctemp;
                                c = Convert.ToDouble(string.Format("{0:0.000}", (ctemp * ques.regular1(b) - b * ques.regular1(a)) / (ques.regular1(b) - ques.regular1(a))));

                                error = Convert.ToDouble(string.Format("{0:0.000}", Math.Abs(c - ctemp)));
                                ctemp = c;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (questions.SelectedIndex == 1)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        if (ques.regular2(i) < 0 && ques.regular2(i + 1) > 0)
                        {
                            a = i;
                            b = i + 1;
                            break;
                        }
                    }

                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }
                    MessageBox.Show(a.ToString());
                    MessageBox.Show(b.ToString());

                    ctemp = Convert.ToDouble(string.Format("{0:0.000}", ((a * ques.regular2(b) - b * ques.regular2(a)) / (ques.regular2(b) - ques.regular2(a)))));

                    error = Math.Abs(ctemp);

                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), string.Format("{0:0.000}", a), string.Format("{0:0.000}", b), string.Format("{0:0.000}", ques.regular2(a)), string.Format("{0:0.000}", ques.regular2(b)), ctemp.ToString(), string.Format("{0:0.000}", ques.regular2(ctemp)), string.Format("{0:0.000}", error));

                            if (ques.regular2(a) * ques.regular2(c) < 0)
                            {
                                b = ctemp;
                                c = Convert.ToDouble(string.Format("{0:0.000}", (a * ques.regular2(b) - ctemp * ques.regular2(a)) / (ques.regular2(b) - ques.regular2(a))));

                                error = Convert.ToDouble(string.Format("{0:0.000}", Math.Abs(c - ctemp)));
                                ctemp = c;
                            }
                            else
                            {
                                a = ctemp;
                                c = Convert.ToDouble(string.Format("{0:0.000}", (ctemp * ques.regular2(b) - b * ques.regular2(a)) / (ques.regular2(b) - ques.regular2(a))));

                                error = Convert.ToDouble(string.Format("{0:0.000}", Math.Abs(c - ctemp)));
                                ctemp = c;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (questions.SelectedIndex == 2)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }

                    for (int i = 0; i < 10; i++)
                    {
                        if (ques.regular3(i) < 0 && ques.regular3(i + 1) > 0)
                        {
                            a = i;
                            b = i + 1;
                            break;
                        }
                    }
                    MessageBox.Show(a.ToString());
                    MessageBox.Show(b.ToString());
                    ctemp = Convert.ToDouble(string.Format("{0:0.000}", ((a * ques.regular3(b) - b * ques.regular3(a)) / (ques.regular3(b) - ques.regular3(a)))));

                    error = Math.Abs(ctemp);

                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), string.Format("{0:0.000}", a), string.Format("{0:0.000}", b), string.Format("{0:0.000}", ques.regular3(a)), string.Format("{0:0.000}", ques.regular3(b)), ctemp.ToString(), string.Format("{0:0.000}", ques.regular3(ctemp)), string.Format("{0:0.000}", error));

                            if (ques.regular3(a) * ques.regular3(c) < 0)
                            {
                                b = ctemp;
                                c = Convert.ToDouble(string.Format("{0:0.000}", (a * ques.regular3(b) - ctemp * ques.regular3(a)) / (ques.regular3(b) - ques.regular3(a))));

                                error = Convert.ToDouble(string.Format("{0:0.000}", Math.Abs(c - ctemp)));
                                ctemp = c;
                            }
                            else
                            {
                                a = ctemp;
                                c = Convert.ToDouble(string.Format("{0:0.000}", (ctemp * ques.regular3(b) - b * ques.regular3(a)) / (ques.regular3(b) - ques.regular3(a))));

                                error = Convert.ToDouble(string.Format("{0:0.000}", Math.Abs(c - ctemp)));
                                ctemp = c;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                a = Convert.ToDouble(txtA.Text);
                b = Convert.ToDouble(txtB.Text);
                if (questions.SelectedIndex == 0)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }



                    ctemp = Convert.ToDouble(string.Format("{0:0.000}", ((a * Convert.ToDouble(string.Format("{0:0.000}", ques.regular1(b))) - b * Convert.ToDouble(string.Format("{0:0.000}", ques.regular1(a)))) / (Convert.ToDouble(string.Format("{0:0.000}", ques.regular1(b))) - Convert.ToDouble(string.Format("{0:0.000}", ques.regular1(a)))))));

                    error = Math.Abs(ctemp);

                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), string.Format("{0:0.000}", a), string.Format("{0:0.000}", b), string.Format("{0:0.000}", ques.regular1(a)), string.Format("{0:0.000}", ques.regular1(b)), ctemp.ToString(), string.Format("{0:0.000}", ques.regular1(ctemp)), string.Format("{0:0.000}", error));

                            if (ques.regular1(a) * ques.regular1(c) < 0)
                            {
                                b = ctemp;
                                c = Convert.ToDouble(string.Format("{0:0.000}", (a * ques.regular1(b) - ctemp * ques.regular1(a)) / (ques.regular1(b) - ques.regular1(a))));

                                error = Convert.ToDouble(string.Format("{0:0.000}", Math.Abs(c - ctemp)));
                                ctemp = c;
                            }
                            else
                            {
                                a = ctemp;
                                c = Convert.ToDouble(string.Format("{0:0.000}", (ctemp * ques.regular1(b) - b * ques.regular1(a)) / (ques.regular1(b) - ques.regular1(a))));

                                error = Convert.ToDouble(string.Format("{0:0.000}", Math.Abs(c - ctemp)));
                                ctemp = c;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (questions.SelectedIndex == 1)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }


                    c     = (a + b) / 2;
                    error = Math.Abs((b - a) / 2);


                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), a.ToString(), b.ToString(), ques.bisection2(a).ToString(), ques.bisection2(b).ToString(), c.ToString(), ques.bisection2(c).ToString(), error.ToString());

                            if (ques.bisection2(a) * ques.bisection2(c) < 0)
                            {
                                b     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                            else
                            {
                                a     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (questions.SelectedIndex == 2)
                {
                    int row = dataGridView1.Rows.Count;
                    if (row > 0)
                    {
                        table.Rows.Clear();
                    }



                    c     = (a + b) / 2;
                    error = Math.Abs((b - a) / 2);


                    for (int i = 0; i < 50; i++)
                    {
                        if (string.Format("{0:0.000}", error) != string.Format("{0:0.000}", 0.000))
                        {
                            table.Rows.Add((i + 1).ToString(), a.ToString(), b.ToString(), ques.bisection3(a).ToString(), ques.bisection3(b).ToString(), c.ToString(), ques.bisection3(c).ToString(), error.ToString());

                            if (ques.bisection3(a) * ques.bisection3(c) < 0)
                            {
                                b     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                            else
                            {
                                a     = c;
                                c     = (a + b) / 2;
                                error = Math.Abs((b - a) / 2);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }