You are on page 1of 15

BT1:

using System;

namespace Bai1
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
System.Console.ReadLine();

}
}
}

BT2:
using System;

namespace Bai2
{
class Program
{
static void Main(string[] args)
{
String ten;
ten = Console.ReadLine();
Console.WriteLine("Xin chào " + ten);

}
}
}

BT3:
using System;

namespace Bai3
{
class Program
{
static void Main(string[] args)
{
int a, b; //Toán hạng
char ch; //Phép toán
Console.Write("Nhap A: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap B: ");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap phep toan: ");
ch = Console.ReadKey().KeyChar;
Console.WriteLine("\n" + TinhToan(a, b, ch));
Console.ReadLine();
}
static string TinhToan(int a, int b, char ch)
{
switch (ch)
{
case '+': return "a + b = " + (a + b);
case '-': return "a - b = " + (a - b);
case '*': return "a * b = " + (a * b);
case '/':
if (b != 0) return "a / b = " + (a / b);
else return "Nhap b khac khong";
default: return "Nhap phep toan khac";
}

}
}
}

BT4:
using System;

namespace Bai4
{
class Program
{
static void Main(string[] args)
{
int a, b;

Console.WriteLine("Nhap a = ");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap b = ");
b = Convert.ToInt32(Console.ReadLine());
if (a == 0)
{
if (b == 0)
{
Console.WriteLine("Phuong trinh vo so nghiem");
}
else
{
Console.WriteLine("Phuong trinh vo nghiem");
}

}
else
{
Console.WriteLine(" Phuong trinh co nghiem x = " + -b / a);
}
Console.ReadKey();

}
}
}

BT5:
using System;

namespace Bai5
{
class Program
{
static void Main(string[] args)
{
int dai, rong, chuVi, dienTich;
Console.WriteLine("Nhap vao chieu dai: ");
dai = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Nhap vao chieu rong: ");
rong = Convert.ToInt32(Console.ReadLine());
chuVi = (dai + rong) * 2;
dienTich = dai * rong;
Console.WriteLine("Chu vi cua hinh chu nhat la: "+ chuVi);
Console.WriteLine("Dien tich cua hinh chu nhat la: " + dienTich);
Console.ReadKey();

}
}
}

BT6:
using System;

namespace Bai6
{
class Program
{
static void Main(string[] args)
{
int banKinh;
double chuVi, dienTich;
const double pi = 3.14;
Console.WriteLine("Nhap vao ban kinh hinh tron");
banKinh = Convert.ToInt32(Console.ReadLine());
chuVi = 2 * pi * banKinh;
dienTich = pi * banKinh * banKinh;
Console.WriteLine("Chu vi cua hinh tron la: " + chuVi);
Console.WriteLine("Dien tich cua hinh tron la: " + dienTich);
Console.ReadKey();

}
}
}

BT7:
using System;

namespace Bai7
{
class Program
{
static void Main(string[] args)
{
int n;
Console.WriteLine("Nhap vao n = ");
n = Convert.ToInt32(Console.ReadLine());
if( n%2 == 0)
{
Console.WriteLine("n la so chan");
}
else
{
Console.WriteLine("n la so le");
}
Console.ReadKey();

}
}
}

BT8:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bai8
{
class Program
{
static void Main(string[] args)
{
int n;
Console.Write("Nhap so tu nhien n: ");
int n = Convert.ToInt32(Console.ReadLine());
if (laSoNguyenTo(n))
{
Console.WriteLine("n la so nguyen to ");
}
else
{
Console.WriteLine(" n KHONG la so nguyen to ");
}
Console.ReadKey();
// Ham kiem tra so nguyen to
}
public static bool laSoNguyenTo(int n)
{
int dem = 0;
for (int i = 1; i <= n; i++)
{
if (n % i == 0)
{
dem++;
}
}
return dem == 2;
}
}
}
BT9:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bai9
{
class Program
{
static void Main(string[] args)
{

int n;
Console.Write("Nhap vao n = ");
n = Convert.ToInt32(Console.ReadLine());
int tonga, tongb, tongc, tongd;
tonga = tongb = tongc = tongd = 0;
//Câu a
Console.WriteLine(" Cau A ");
for (int i = 1; i <= n; i++)
{
Console.Write(i + " - ");
tonga += i;
}
Console.WriteLine(" Tong = " + tonga);
//Câu b
Console.WriteLine(" Cau B ");
for (int i = 1; i <= n; i++)
{
if (i % 2 == 0)
{
Console.Write(i + " - ");
tongb += i;
}
}
Console.WriteLine(" Tong = " + tongb);
//Câu C
Console.WriteLine(" Cau C ");
for (int i = 1; i <= n; i++)
{
if (i % 2 != 0)
{
Console.Write(i + " - ");
tongc += 1;
}
}
Console.WriteLine(" Tong = " + tongc);
//Câu D
Console.WriteLine(" Cau D ");
for (int i = 1; i <= n; i++)
{
if (laSoNguyenTo(i))
{
Console.Write(i + " - ");
tongd += i;
}
}
Console.WriteLine(" Tổng = " + tongd);
Console.ReadKey();

}
public static bool laSoNguyenTo(int n)
{
int dem = 0; //bien dem
for (int i = 1; i <= n; i++)
{
if (n % i == 0)
{
dem++;
}

}
}
}
}

BT10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bai10
{
class Program
{
static void Main(string[] args)
{
Console.Write("Nhap vao so luong sinh vien = ");
n = Convert.ToInt32(Console.ReadLine());
String maSinhVien = "";
String hoTenSinhVien = "";
double diemToan = 0.0;
double diemLy = 0.0;
double diemHoa = 0.0;
for (int i = 1; i <= n; i++)
{
Console.WriteLine("Nhap vao thong tin sinh vien thu" + i);
Console.WriteLine("Nhap vao ma sinh vien");
maSinhVien = Console.ReadLine();
Console.WriteLine("Nhap vao ho va ten sinh vien");
hoTenSinhVien = Console.ReadLine();
Console.WriteLine("Nhap vao diem mon Toan ");
diemToan = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Nhap vao diem mon Ly ");
diemLy = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Nhap vao diem mon Hoa ");
diemHoa = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Da nhap xong thong tin cua sinh vien thu", +i);

}
for (int i = 1; i <= n; i++)
{
Console.WriteLine("Sinh vien thu " + i);
Console.WriteLine("Ma sinh vien: ", +maSinhVien);
Console.WriteLine("Ho va ten sinh vien: ", +hoTenSinhVien);
Console.WriteLine("Diem mon Toan: " + diemToan);
Console.WriteLine("Diem mon Ly: " + diemLy);
Console.WriteLine("Diem mon Hoa: " + diemHoa);

}
Console.ReadKey();
}
}
}

You might also like