trang Blog

khocoaoaTham gia: 31/07/2009
  • Giai Phuong trinh trung phuong ax4+bx2+c=0
    Thư Giãn
    CameraNikon D3
    ISO3200
    Aperturef/8
    Exposure1/50th
    Focal Length200mm

    Giai Phuong trinh trung phuong ax4+bx2+c=0

               
    double a = double.Parse(txta.Text);double b = double.Parse(txtb.Text);double c = double.Parse(txtc.Text);double X = 0;double x1 = 0;double x2 = 0;double data = 0; 

     

     

     

     

     

     

     

     

     if (a == 0)
                {
                    lblketqua.Text = " gia tri ko hop le. a phải khác 0!";
                }
                else if (a > 0)
                {
                    data = -b / (2 * a);
                    if (data < 0)
                    {
                        lblketqua.Text = "Vô nghiệm";
                    }
                    else if (data == 0)
                    {
                        x1 = x2 = Math.Sqrt(data);
                        lblketqua.Text ="nghiệm x1="+ x2.ToString()+", "+"x2="+x1.ToString();
                    }
                    else if (data > 0)
                    {
                        x1 = (-b + Math.Sqrt(data)) / 2 * a;
                        x2 = (-b -Math.Sqrt(data)) / 2 * a;
                        if (x1 < 0 && x2 < 0)
                        {
                            lblketqua.Text = "Vô nghiệm";
                        }
                        else if (x1 > 0 && x2 > 0)
                        {
                            x1 = Math.Sqrt(x1);
                            x2 = Math.Sqrt(x2);
                            lblketqua.Text = "x1=" + x1.ToString() + ", " + "x2= " + " " + x2.ToString();
                        }
                    }

                }

     

     

     
    Giai Phuong trinh trung phuong ax4+bx2+c=0