Một số bài tập C# cơ bản và nâng cao

9 1.8K 77
Một số bài tập C# cơ bản và nâng cao

Đang tải... (xem toàn văn)

Thông tin tài liệu

C căn bản, dành cho những ai mới bước vào lập trình c, Những bài tập C ứng dụng cho việc học C cho người mới. Những bài tập liên quan tới thuật toán, những bài ứng dụng trong tuyển dụng phỏng vấn xin việc và một số bài toán kinh điển lập trình ........................................................................Giải phương trình bậc 2, tính giai thừa, tìm số lớn nhất, tính diện tích hình, in tam giác,...... rất nhiều bài toán khác trong tài liệuNếu bạn nào cần liên hệ vui lòng liên hệ theo:Facebook: iletaiBlog: letaii.blogspot.comChúc các bạn làm chủ được ngôn ngữ Csharp hiệu quả

Bài tập C# - Lê Quang Trọng Tài BÀI TẬP KIỂM TRA 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 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(); } } } BÀI TẬP TÍNH TỔNG DÃY SỐ using System; namespace BAITAP Bài tập C# - Lê Quang Trọng Tài { class CsharpTL { public static void Main() { int j, sum = 0; Console.Write("\n"); Console.Write("Tinh tong day so C#:\n"); Console.Write(" -"); Console.Write("\n\n"); Console.Write("10 so tu nhien dau tien la:\n"); for (j = 1; j %lt;= 10; j++) { sum = sum + j; Console.Write("{0} ", j); } Console.Write("\nTong cua 10 so tren la: {0}\n", sum); 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 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 num2) { if (num1 > num3) { Console.Write("So thu nhat la so lon nhat ba so \n\n"); } else { Console.Write("So thu ba la so lon nhat ba so \n\n"); } } else if (num2 > num3) Console.Write("So thu hai la so lon nhat ba so.\n\n"); else Console.Write("So thu ba la so lon nhat ba so \n\n"); Console.ReadKey(); } } } TÍNH DIỆN TÍCH HÌNH: using System; namespace BAITAP { class CsharpTL { public static void Main() { Bài tập C# - Lê Quang Trọng Tài int lua_chon, r, l, w, b, h; double dien_tich = 0; Console.Write("\n"); Console.Write("Chuong trinh C# duoi dang mot menu co cac lua chon de tinh dien tich:\n"); Console.Write(" "); Console.Write("\n\n"); Console.Write("Lua chon 1: tinh dien tich hinh tron\n"); Console.Write("Lua chon 2: tinh dien tich hinh chu nhat\n"); Console.Write("Lua chon 3: tinh dien tich hinh tam giac\n"); Console.Write("Nhap lua chon cua ban: "); lua_chon = Convert.ToInt32(Console.ReadLine()); switch (lua_chon) { case 1: Console.Write("Nhap ban kinh hinh trong: "); r = Convert.ToInt32(Console.ReadLine()); 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; namespace BAITAP { class CsharpTL { public static void Main() { int i, f = 1, num; Console.Write("\n"); Console.Write("Tim giai thua C#:\n"); Console.Write(" "); Console.Write("\n\n"); Console.Write("Nhap mot so bat ky: "); num = Convert.ToInt32(Console.ReadLine()); for (i = 1; i

Ngày đăng: 12/06/2017, 13:38

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan