Giải phương trình bậc 2 trong C |
public void Nhap()
{
Console.Write("\t Nhap he so a: ");
this.a = float.Parse(Console.ReadLine());
Console.Write("\t Nhap he so b: ");
this.b = float.Parse(Console.ReadLine());
Console.Write("\t Nhap he so c: ");
this.c = float.Parse(Console.ReadLine());
}
public void GiaiPT()
{
float delta, x1, x2;
delta = this.b * this.b - 4 * this.a * this.c;
if (delta > 0)
{
x1 = (float)(-this.b - Math.Sqrt(delta)) / (2 * this.a);
x2 = (float)(-this.b + Math.Sqrt(delta)) / (2 * this.a);
Console.WriteLine("\n Phuong trinh co 2 nghiem la X1 = {0} va X2 = {1}", x1.ToString("0.000"), x2.ToString("0.000"));
}
else if (delta == 0)
{
x1 = (-this.b) / (2 * this.a);
Console.WriteLine("\n Phuong trinh co nghiem duy nhat X = {0}", x1.ToString("0.000"));
}
else
Console.WriteLine("\n Phuong trinh vo nghiem");
}
Ý kiến bạn đọc [ 0 ]
Ý kiến của bạn