You are on page 1of 3

using System;

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;

Bai_Tap_6();

Console.ReadKey();

// Chuyen so thap phan sang nhi phan


static void Bai_Tap_4()
{
// Nhap vao n
Console.Write("Nhập vào số n: ");
int n = int.Parse(Console.ReadLine());

int k = n;
string NhiPhan="";

do
{
NhiPhan = (n % 2).ToString() + NhiPhan;
n = n / 2;

} while (n > 0);

Console.WriteLine("Chuoi nhi phan của {0} la {1} ",k, NhiPhan);

// đoán số
static void Bai_Tap_6()
{
// Tạo ngẫu nhiên 1 số từ 0..99
Random rnd = new Random();
int SoNN = rnd.Next(65, 91);
char RanChar = Convert.ToChar(SoNN);
Console.WriteLine(RanChar);

////Console.WriteLine(SoNN);
//int SoBK = 0;

//// Cho user đoán số


//Console.Write("Đoán số của bạn (0-99): ");
//SoBK = int.Parse(Console.ReadLine());
//// Lặp lại đoán số trong 6 lần

//int sai = 0;
//if (SoBK == SoNN) { }
//else
//{
// do
// {
// sai++;
// Console.Write("Doan sai, moi ban doan lai: ");
// SoBK = int.Parse(Console.ReadLine());
// if (SoBK == SoNN) break;

// } while (sai < 5);

//}
//if (sai == 5)
//{
// Console.WriteLine("Ban da doan sai du 6 lan!!!");
//}
//else
//{
// Console.WriteLine("Ban doan dung so nn la " + SoNN);
//}
}

static void Vi_du()


{
int n = 0;

do
{
// Cac cau lenh muon thuc hien
Console.Write("Nhap vao so n > 0: ");
n = int.Parse(Console.ReadLine());
if (n <= 0)
{
Console.WriteLine("Nhap sai. Vui long nhap lai");
}

}
// Lặp lại các câu lệnh trong do đến khi nào n>0
while (n <= 0);

int dem = 0;

while (dem < n)


{
Console.WriteLine("Number: " + dem);
dem++;
}

double gt = 1;
do
{
gt = gt * n;
Console.WriteLine("Giai thua = " + gt);
n--;
Console.WriteLine("n = " + n);
}
while (n > 0);

Console.WriteLine("Giai thua cuoi cung = " + gt);


}

// Chu rot tren man hinh


static void Bai_Tap_2()
{
// Nhap chuoi can rot
Console.Write("Nhap chuoi: ");
string ChuoiRoi = Console.ReadLine();

ConsoleKeyInfo PhimBam;

// Vong lap tang vi tri dong cua con tro chuot


for (int i = 0; i <= Console.WindowHeight; i++)
{
// Kiểm tra xem có nhấn phím hay không?
if (Console.KeyAvailable)
{
// Gán phím nhấn vào biến PhimBam
PhimBam = Console.ReadKey();
Console.WriteLine(PhimBam.Key);

//Kiểm tra PhimBam có phải là phím Escape hay không?


if (PhimBam.Key == ConsoleKey.Escape) break;

// Xac dinh vi tri ban dau


Console.SetCursorPosition(Console.WindowWidth/2, i);

// In chuoi
Console.Write(ChuoiRoi);

// Thiet lap thoi gian xuat hien


System.Threading.Thread.Sleep(1000);

// Xoa man hinh


Console.Clear();
}

}
}

You might also like