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ả
Trang 1BÀ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();
}
}
}
BÀI TẬP TÍNH TỔNG DÃY SỐ
using System;
namespace BAITAP
Trang 2class CsharpTL
{
public static void Main()
{
int j, sum = 0
Console.Write("\n");
Console.Write("Tinh tong day so trong 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()
{
Trang 3Console.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 <= number; i++)
if number % i == )
bien_dem++;
if bien_dem == )
Console.WriteLine("So da cho la so nguyen to.");
else
Console.WriteLine("So da cho khong phai la so nguyen to.");
Console.ReadKey();
}
}
}
TÍNH TỔNG CÁC SỐ LẺ
using System;
namespace BAITAP
{
class CsharpTL
{
public static void Main()
{
Trang 4int i, n, sum = 0
Console.Write("\n");
Console.Write("Hien thi va tinh tong n so le trong C#:\n");
Console.Write(" -");
Console.Write("\n\n");
Console.Write("Nhap so cac so: ");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("\nHien thi cac so le: ");
for i = 1 i <= n; i++)
{
Console.Write("{0} ", 2 * i - 1);
sum += 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");
Trang 5Console.Write(" -");
Console.Write("\n\n");
Console.Write("Nhap mot so nguyen bat ky: ");
num1 = Convert.ToInt32(Console.ReadLine());
rem1 = num1 % 2
if rem1 == )
Console.WriteLine("{0} la so chan.\n", num1);
else
Console.WriteLine("{0} la so le.\n", num1);
Console.ReadKey();
}
}
}
TÌM SỐ LỚN NHẤT:
using System;
namespace BAITAP
{
class CsharpTL
{
public static void Main()
{
int num1, num2, num3;
Console.Write("\n");
Console.Write("Chuong trinh C# de tim so lon nhat trong 3 so:\n");
Console.Write(" -");
Console.Write("\n\n");
Console.Write("Nhap so thu nhat: ");
num1 = Convert.ToInt32(Console.ReadLine());
Trang 6Console.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;
namespace BAITAP
{
class CsharpTL
{
public static void Main()
{
Trang 7int 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 :
Console.Write("Nhap ban kinh hinh trong: ");
r = Convert.ToInt32(Console.ReadLine());
dien_tich = 3.14 r * r;
break;
case :
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 :
Trang 8Console.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 trong C#:\n");
Console.Write(" -");
Console.Write("\n\n");
Console.Write("Nhap mot so bat ky: ");
num = Convert.ToInt32(Console.ReadLine());
for i = 1 i <= num; i++)
Trang 9Console.Write("Giai thua cua {0} la: {1}\n", num, f);
Console.ReadKey();
}
}
}