CCCCC
CCCCC
if (a != 0)
{
if (detal > 0)
{
Console.WriteLine("Phuong Trinh Co 2 Nghiem Phan Biet:");
double x1 = (-b + Math.Sqrt(detal)) / (2 * a);
double x2 = (-b - Math.Sqrt(detal)) / (2 * a);
Console.WriteLine($"Nghiem x1 = {x1}");
Console.WriteLine($"Nghiem x2 = {x2}");
}
if (detal == 0)
{
Console.WriteLine("Phuong Trinh Co 1 Nghiem Kep");
double x = -b / (2 * a);
Console.WriteLine($"Ket Qua:{x}");
}
if (detal < 0)
{
Console.WriteLine("Phuong Trinh Vo Nghiem (khong co nghiem thuc, chi co nghiem
phuc)");
}
}
Console.ReadKey();
}
}
Bai 7
static void Main(string[] args)
{
Console.Write("Nhap mot so: ");
int number = int.Parse(Console.ReadLine());
if (number % 2 == 0)
{
Console.WriteLine("So chan");
}
else
{
Console.WriteLine("So le");
}
Console.ReadKey();
Bai 3
static void Main(string[] args)
{
Console.Write("Nhap diem tong ket: ");
double diemTK = double.Parse(Console.ReadLine());
switch (diemTK)
{
case double d when (d >= 0 && d <= 3.0):
Console.WriteLine("Hoc luc: Kem");
break;
case double d when (d > 3.0 && d <= 4.0):
Console.WriteLine("Hoc luc: Yeu");
break;
case double d when (d > 4.0 && d <= 6.0):
Console.WriteLine("Hoc luc: Trung binh");
break;
case double d when (d > 6.0 && d <= 8.0):
Console.WriteLine("Hoc luc: Kha");
break;
case double d when (d > 8.0 && d <= 10.0):
Console.WriteLine("Hoc luc: Gioi");
break;
default:
Console.WriteLine("Diem khong hop le.");
break;
}
Console.ReadKey();
Bai7
static void Main(string[] args)
{
Console.Write("Nhap ngay: ");
int day = int.Parse(Console.ReadLine());
Console.Write("Nhap thang: ");
int month = int.Parse(Console.ReadLine());
Console.Write("Nhap nam: ");
int year = int.Parse(Console.ReadLine());
try
{
DateTime currentDate = new DateTime(year, month, day);
DateTime yesterday = currentDate.AddDays(-1);
DateTime tomorrow = currentDate.AddDays(1);
Console.ReadKey();
}
Bai 3
static void Main(string[] args)
{
Console.Write("Nhap mot so: ");
int n = int.Parse(Console.ReadLine());
if (n < 2)
{
Console.WriteLine("Khong phai so nguyen to.");
return;
}
if (laSoNguyenTo)
Console.WriteLine("La so nguyen to.");
else
Console.WriteLine("Khong phai so nguyen to.");
Console.ReadKey();
Bai 7
Console.Write("Nhap so nguyen n: ");
int n = int.Parse(Console.ReadLine());
double tong = 0;
for (int i = 1; i <= n; i++)
{
tong += 1.0 / i;
}
Console.WriteLine($"Tong nghich dao cua {n} so nguyen dau tien la: {tong:F4}");
3
Console.Write("Nhap mot so: ");
string number = Console.ReadLine();
string[] digits = { "Khong", "Mot", "Hai", "Ba", "Bon", "Nam", "Sau", "Bay", "Tam", "Chin" };
int j = 0;
while (j < number.Length)
{
if (char.IsDigit(number[j]))
{
int num = int.Parse(number[j].ToString());
Console.Write(digits[num] + " ");
}
j++;
}
Console.WriteLine();
Console.Re adKey();
3
static void NhapHeSo(out double a, out double b)
{
Console.Write("Nhap he so a: ");
a = double.Parse(Console.ReadLine());
Console.Write("Nhap he so b: ");
b = double.Parse(Console.ReadLine());
}
7
static void NhapHeSo(out double a, out double b)
{
Console.Write("Nhap he so a: ");
a = double.Parse(Console.ReadLine());
Console.Write("Nhap he so b: ");
b = double.Parse(Console.ReadLine());
}
3
static void NhapHeSo(out double a, out double b)
{
Console.Write("Nhap he so a: ");
a = double.Parse(Console.ReadLine());
Console.Write("Nhap he so b: ");
b = double.Parse(Console.ReadLine());
}
7
static void NhapHeSo(out double a, out double b)
{
Console.Write("Nhap he so a: ");
a = double.Parse(Console.ReadLine());
Console.Write("Nhap he so b: ");
b = double.Parse(Console.ReadLine());
}
double sum = 0;
for (int i = 0; i < N; i++)
{
sum += arr[i];
}
double avg = sum / N;
Console.WriteLine($"\\nTrung binh cong cua mang la: {avg}");
Console.WriteLine("Cac phan tu lon hon trung binh cong la:");
bool found = false;
for (int i = 0; i < N; i++)
{
if (arr[i] > avg)
{
Console.Write(arr[i] + " ");
found = true;
}
}
if (!found)
{
Console.WriteLine("Khong co phan tu nao lon hon trung binh cong.");
}
Console.ReadKey();
}