You are on page 1of 4

Câu 1.

using System;

namespace HongNguyen
{
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("Nhập 3 chữ cái và hiển thị theo chiều ngược lại:");
string a = Console.ReadLine();
string b = Console.ReadLine();
string c = Console.ReadLine();
Console.WriteLine("3 chữ cái hiển thị theo chiều ngược lại: {0}, {1}, {2}",
c, b, a);

}
}
}

Câu 2. Tam giác cân


int i, j, bien_dem, so_hang, k, t = 1;
Console.Write("\n");
Console.Write("Ve tam giac so can”);

Console.Write("Nhap so hang: ");


so_hang = Convert.ToInt32(Console.ReadLine());
bien_dem = so_hang + 3;
for (i = 1; i <= so_hang; i++)
{
for (k = bien_dem; k >= 1; k--)
{
Console.Write(" ");
}
for (j = 1; j <= i; j++)
Console.Write("{0} ", t++);
Console.Write("\n");
bien_dem--;

}
}

Tam giác vuông:

Console.OutputEncoding = System.Text.Encoding.UTF8;
int n, i, j;
Console.WriteLine("Vẽ tam giác vuông:");
Console.Write("Nhap so hang: ");
n = Convert.ToInt32(Console.ReadLine());
for ( i = 0; i <= n; i++)
{
for ( j = 0; j < i; j++)
Console.Write(j);
Console.Write("\n");
}

Câu 3.

Console.OutputEncoding = System.Text.Encoding.UTF8;
string system_usernam = "HongNguyen", system_password = "1511";
Console.WriteLine("Hãy nhập usernam và password");
string username = Console.ReadLine();
string password = Console.ReadLine();
if (username == system_usernam && password == system_password)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Bạn đã đăng nhập thành công");
}
else
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Bạn đã đăng nhập thất bại");
}

Câu 6.

double chu_vi, s, r;
double PI = 3.14;

Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("Hãy nhập bán kính r:");
r =int.Parse (Console.ReadLine());

chu_vi = 2 * PI * r;
Console.WriteLine("Chu vi hình tròn là {0}", chu_vi);
s = PI * Math.Pow(r, 2);

Console.WriteLine("Diện tích hình tròn là {1}", s);


Console.ReadKey();

Câu 7

double y;

Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("Giải phương trình:y=a*x*x+b*x+c");
Console.Write("a=\n");
double a = double.Parse(Console.ReadLine());
Console.Write("b=\n");
double b = double.Parse(Console.ReadLine());
Console.Write("c=\n");
double c = double.Parse(Console.ReadLine());
Console.Write("x=\n");
double x = double.Parse(Console.ReadLine());
y = a * Math.Pow(x, 2) + b * x + c;
Console.WriteLine("Phương trình y có giá trị là: {0}", y);

Câu 8

float quang_duong, gio, giay, phut, timesec, mps, khp, mph;


Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.Write("Nhập quãng đường (đơn vị met): ");
quang_duong = float.Parse(Console.ReadLine());
Console.Write("Nhập thời gian (giờ): ");
gio = float.Parse(Console.ReadLine());
Console.Write("Nhập thời gian (phút): ");
phut = float.Parse(Console.ReadLine());
Console.Write("Nhập thời gian (giây): ");
giay = float.Parse(Console.ReadLine());
timesec = (gio * 3600) + (phut * 60) + giay;
mps = quang_duong / timesec;
khp = (quang_duong / 1000.0f) / (timesec / 3600.0f);
mph = khp / 1.609f;
Console.WriteLine("Vận tốc là {0} m/s", mps);
Console.WriteLine("Vận tốc là {0} km/h", khp);
Console.WriteLine("Vận tốc là {0} mile/h", mph);

Câu 9

double r, s, v;
double PI = 3.14;

Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.Write("Nhập bán kính hình cầu r: ");
r = float.Parse(Console.ReadLine());

s = 4 * PI * Math.Pow(r, 2);
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("Diện tích hình cầu là: {0}", s);
v = (4 / 3 )* PI * Math.Pow(r, 3);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("Thể tích hình cầu là: {0}", v);
Câu 10
char ch;
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("Hãy nhập kí tự bất kì:");
ch = Convert.ToChar(Console.ReadLine());
if (ch >= 'a' && ch <= 'z')
Console.WriteLine("Chu cai in thuong");
else if (ch >= 'A' && ch <= 'Z')
Console.WriteLine("Chu cai in hoa");
else if (ch >= '1' && ch <= '9')
Console.WriteLine("Chu so");
else
Console.WriteLine("Ki tu dac biet");
Cách 2
char symbol;

Console.Write("Nhap mot ky tu bat ky: ");


symbol = Convert.ToChar(Console.ReadLine());

if ((symbol == 'a') || (symbol == 'e') || (symbol == 'i') ||


(symbol == 'o') || (symbol == 'u'))
Console.WriteLine("Ky tu vua nhap la nguyen am.");
else if ((symbol >= '0') && (symbol <= '9'))
Console.WriteLine("Ky tu vua nhap la chu so.");
else
Console.Write("Ky tu vua nhap khong phai nguyen am va chu so.");
Câu 11
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.Write("Nhập số bất kì: ");
double q = double.Parse(Console.ReadLine());
Console.WriteLine("Số này là {0} ", (q % 2 == 0) ? "số chẵn" : "số lẻ");
Câu 12
Console.OutputEncoding = System.Text.Encoding.UTF8;
int n, i, j, binno = 0, dn;
Console.Write("\n");
Console.Write("Chuyen doi thap phan thanh nhi phan trong:\n");

Console.Write("Nhap mot so thap phan bat ky: ");


n = Convert.ToInt32(Console.ReadLine());
dn = n;
i = 1;
for (j = n; j > 0; j = j / 2)
{
binno = binno + (n % 2) * i;
i = i * 10;
n = n / 2;

You might also like