Bài tập C# - Lê Quang Trọng Tài
BÀI TẬP KIỂM TRA 2 SỐ BẰNG NHAU:
using System;
namespace BAITAP
{
class CsharpTL
{
public static void Main()
{
int int1, int2;
Console.Write("\n\n");
Console.Write("Chuong trinh C# kiem tra hai so co bang nhau khong:\n");
Console.Write("-------------------------------------------");
Console.Write("\n\n");
Console.Write("Nhap so thu nhat: ");
int1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap so thu hai: ");
int2 = Convert.ToInt32(Console.ReadLine());
if (int1 == int2)
Console.WriteLine("{0} va {1} la bang nhau.\n", int1, int2);
else
Console.WriteLine("{0} va {1} la khong bang nhau.\n", int1, int2);
Console.ReadKey();
}
}
}
}
}
using System;
KIỂM TRA SỐ NGUYÊN TỐ
namespace BAITAP
{
class CsharpTL
{
public static void Main()
{
Bài tập C# - Lê Quang Trọng Tài
Console.Write("\n");
Console.Write("Kiem tra so nguyen to trong C#:\n");
Console.Write("----------------------------");
Console.Write("\n\n");
int number;
int bien_dem = 0;
Console.Write("Nhap mot so bat ky: ");
number = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i
{
Console.Write("{0} ", 2 * i - 1);
sum += 2 * i - 1;
}
Console.Write("\nTong {0} so le ban dau la: {1} \n", n, sum);
Console.ReadKey();
}
}
}
KIỂM TRA SỐ CHẲN LẺ:
using System;
namespace BAITAP
{
class CsharpTL
{
public static void Main()
{
int num1, rem1;
Console.Write("\n\n");
Bài tập C# - Lê Quang Trọng Tài
Console.Write("Kiem tra chan le trong C#:\n");
Console.Write("---------------------------------------");
Console.Write("\n\n");
Console.Write("Nhap mot so nguyen bat ky: ");
Bài tập C# - Lê Quang Trọng Tài
Console.Write("Nhap so thu hai: ");
num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap so thu ba: ");
num3 = Convert.ToInt32(Console.ReadLine());
if (num1 > num2)
{
if (num1 > num3)
{
Console.Write("So thu nhat la so lon nhat trong ba so. \n\n");
}
else
{
Console.Write("So thu ba la so lon nhat trong ba so. \n\n");
}
}
else if (num2 > num3)
Console.Write("So thu hai la so lon nhat trong ba so.\n\n");
else
Console.Write("So thu ba la so lon nhat trong ba so. \n\n");
Console.ReadKey();
}
}
}
TÍNH DIỆN TÍCH HÌNH:
using System;
dien_tich = 3.14 * r * r;
break;
case 2:
Console.Write("Nhap chieu dai HCN: ");
l = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap chieu rong HCN: ");
w = Convert.ToInt32(Console.ReadLine());
dien_tich = l * w;
break;
case 3:
Bài tập C# - Lê Quang Trọng Tài
Console.Write("Nhap canh huyen tam giac:");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap chieu cao tam giac:");
h = Convert.ToInt32(Console.ReadLine());
dien_tich = 0.5 * b * h;
break;
}
Console.Write("Dien tich hinh la: {0}\n", dien_tich);
Console.ReadKey();
}
}
}
TÍNH GIAI THỪA:
using System;