Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Câu 4.

Console.OutputEncoding = System.Text.Encoding.UTF8;
int năm;
Console.BackgroundColor = ConsoleColor.DarkGreen;
Console.Write(" Nhập năm cần kiểm tra: ");
năm = int.Parse(Console.ReadLine());
if (năm % 400 == 0 || năm % 4 == 0 && năm % 100 != 0)
Console.WriteLine("{0} là năm nhuận", năm);
else Console.WriteLine("{0} không phải là năm nhuận", năm);

}
}
}
Câu 5.
Console.OutputEncoding = System.Text.Encoding.UTF8;
int tuổi;
Console.Write("Nhập số tuổi để kiểm tra: ");
tuổi = int.Parse(Console.ReadLine());
if (tuổi >= 18)
{
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("Bạn đã đủ tuổi để tham gia bầu cử");
}
else
{
Console.BackgroundColor = ConsoleColor.Red;
Console.WriteLine("Xin lỗi, bạn không đủ tuổi để tham gia bầu cử");
}

Console.ReadKey();

}
}
}
Câu 7.
Console.OutputEncoding = System.Text.Encoding.UTF8;
float chiều_cao;
Console.Write("Hãy nhập chiều cao của bạn: ");
chiều_cao =Convert.ToInt32(Console.ReadLine());
if(chiều_cao<=150.0)
{
Console.BackgroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("Có vẻ như bạn khá thấp");
}
else if(chiều_cao>150.0 && chiều_cao <170.0)
Console.WriteLine("Bạn có chiều cao trung bình");
else Console.WriteLine("Bạn cao lắm đấy nhé !!!");

Console.ReadKey();

}
}
}

Câu 8.
Console.OutputEncoding = System.Text.Encoding.UTF8;
float x, y;
Console.WriteLine("Hãy nhập tọa độ x,y");
Console.Write("Nhập hoành độ\nx = ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhập tung độ\ny = ");
y = Convert.ToInt32(Console.ReadLine());

if (x > 0 && y > 0)


Console.Write("Điểm có tọa độ ({0} {1}) thuộc góc phần tư thứ nhất", x,
y);
else if (x < 0 && y > 0)
Console.Write("Điểm có tọa độ ({0} {1} thuộc góc phần tư thứ hai", x, y);
else if (x < 0 && y < 0)
Console.Write("Điểm có tọa độ ({0} {1} thuộc góc phàn tư thứ ba", x, y);
else if (x > 0 && y < 0)
Console.Write("Điểm có tọa độ ({0} {1}) thuộc góc phần tư thứ tư", x, y);
Console.ReadKey();

Câu 10.

Console.OutputEncoding = System.Text.Encoding.UTF8;
float sum;
Console.WriteLine("Hãy nhập điểm Toán Lý Hóa");
Console.Write("Điểm toán = ");
float toán = Convert.ToSingle(Console.ReadLine());
Console.Write("Điểm lý = ");
float lý = Convert.ToSingle(Console.ReadLine());
Console.Write("Điểm hóa = ");
float hóa = Convert.ToSingle(Console.ReadLine());
sum = toán + lý + hóa;
if (toán >= 6.0 && lý >= 6.0 && hóa >= 6.0)

if (sum >= 18)


{
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("Chúc mừng bạn đã trúng tuyển");
}
else
Console.WriteLine("Rất tiếc, bạn đã không trúng tuyển");
else Console.WriteLine("Rất tiếc, bạn đã không trúng tuyển");
Console.ReadKey();

}
}
}

Câu 13.

Console.OutputEncoding = System.Text.Encoding.UTF8;

Console.WriteLine("Nhập 3 cạnh của tam giác");


Console.Write("Cạnh a = ");
int a = int.Parse(Console.ReadLine());
Console.Write("Cạnh b = ");
int b = int.Parse(Console.ReadLine());
Console.Write("Cạnh c = ");
int c =int.Parse( Console.ReadLine());
if (a == b && a == c)
Console.WriteLine("Đây là tam giác đều");
else if (a == b|| b==c||a==c)
Console.WriteLine("Đây là tam giác cân");
else Console.WriteLine("Đây là tam giác lệch");
Console.ReadKey();

Câu 20.

Console.OutputEncoding = System.Text.Encoding.UTF8;

Console.Write("Hãy nhập tháng cần kiểm tra: ");


int tháng = int.Parse(Console.ReadLine());
switch (tháng)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
Console.WriteLine("Tháng có 31 ngày");
break;
case 2:
Console.WriteLine("Tháng có 28 ngày");
break;
case 4:
case 6:
case 9:
case 11:
Console.WriteLine("Tháng có 30 ngày");
break;
default:
Console.WriteLine("Tháng bạn nhập không hợp lệ");
break;
}
Console.ReadKey();

}
}
}
Câu 21.
Console.OutputEncoding = System.Text.Encoding.UTF8;
const double pi = 3.14159;
double dien_tich=0, r, cạnh_a, cạnh_b, m, h;

Console.WriteLine("Lựa chọn 1 : tính diện tích hình tròn");


Console.WriteLine("Lựa chọn 2: tính diện tích hình chữ nhật");
Console.WriteLine("Lựa chọn 3: tính diện tích hình tam giác");
Console.WriteLine(" Hãy nhập lựa chọn của bạn ");
int lựa_chọn = int.Parse(Console.ReadLine());
switch (lựa_chọn)
{
case 1:
Console.Write("Bán kính r = ");
r = Convert.ToInt32(Console.ReadLine());
dien_tich = pi * Math.Pow(r, 2);
break;
case 2:
Console.Write("Nhập chiều dài cạnh_a: ");
cạnh_a = Convert.ToDouble(Console.ReadLine());
Console.Write("Nhập chiều rộng cạnh_b: ");
cạnh_b = Convert.ToDouble(Console.ReadLine());
dien_tich = cạnh_a * cạnh_b;
break;
case 3:
Console.WriteLine("Nhập cạnh huyền tam giác: ");
m = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Nhập chiều cao tam giác: ");
h = Convert.ToDouble(Console.ReadLine());
dien_tich = 0.5 * m * h;
break;
}
Console.WriteLine("Diện tích hình là {0}", dien_tich);
Console.ReadKey();

}
}
}

Câu 22.

Console.OutputEncoding = System.Text.Encoding.UTF8;
int số_1, số_2;
Console.WriteLine("Nhập hai số a và b");
Console.Write("a= ");
số_1 = Convert.ToInt32(Console.ReadLine());
Console.Write("b= ");
số_2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("1. Phép cộng hai số \n2. Phép trừ hai số\n3. Phép nhân hai
số\n4. Phép chia hai số ");
Console.Write("Hãy nhập lựa chọn của bạn: ");
int lua_chon = int.Parse(Console.ReadLine());
switch (lua_chon)
{
case 1:
Console.WriteLine("Tổng của hai số {1} và {0} là {2}", số_1, số_2,
số_1 + số_2);
break;
case 2:
Console.WriteLine("Hiệu của hai số {1} và {0} là {2}", số_1, số_2,
số_1 - số_2);
break;
case 3:
Console.WriteLine("Tích của hai số {1} và {0} là {2}", số_1, số_2,
số_1 * số_2);
break;
case 4:
if (số_2 == 0)
Console.WriteLine("Với b = 0, không thực hiện được phép tính");
else Console.WriteLine("Thương của hai số {1} và {0} là {2}", số_1,
số_2, số_1 / số_2);
break;
}

Console.ReadKey();

}
}
}

You might also like