38
1
using System;
2
3
public class PhuongTrinhBacHai
4
{
5
public static void Main()
6
{
7
//Khai báo biến
8
Double a,b,c,root1,root2,delta;
9
//Nhập dữ liệu vào cho các biến
10
Console.WriteLine("Nhập vào hệ số a, b, c của phương trình ax2 + bx +c:");
11
Console.Write("Nhap a:");
12
a = Double.Parse(Console.ReadLine());
13
Console.Write("Nhap b:");
14
b = Double.Parse(Console.ReadLine());
15
Console.Write("Nhap b:");
16
c = Double.Parse(Console.ReadLine());
17
//Tính delta của phương trình
18
delta = b*b - 4*a*c;
19
if(delta>0)
20
{
21
//Có hai nghiệm phân biệt
22
root1 = (-b + Math.Sqrt(delta))/(2*a);
23
root2 = (-b - Math.Sqrt(delta))/(2*a);
24
Console.WriteLine("Phương trình có hai nghiệm phân biệt:");
25
Console.WriteLine("x1 = "+root1 + ", x2 = " + root2);
26
}
27
else if(delta == 0)
28
{
29
//Có nghiệm kép
30
root1=root2 = -b/(2*a);
31
Console.WriteLine("Phương trình có nghiệm kép:");
32
Console.WriteLine("x1 = x2 = " + root2);
33
}
34
else
35
Console.WriteLine("Phương trình vô nghiệm");
36
37
}
38
}
Cached Result