Mã: Chọn tất cả
(* PHAN KHAI BAO - Khong nhat thiet phai co, tuy thuoc vao PHAN THAN *)
PROGRAM // Khai bao ten chuong trinh, chi duy nhat 1 ten, khong khai bao van hop le
My_Program;
USES // Khai bao cac thu vien, co the khai bao thua, nhung khong the thieu
CRT;
VAR // Khai bao cac bien, co the khai bao thua, nhung khong the thieu
// So nguyen co gia tri trong khoang 0 den 255
Bien_Dem, Bien_Byte: BYTE;
// So nguyen co gia tri trong khoang -2^15 den 2^15 - 1
Bien_SoNguyen: INTEGER;
// So thuc co gia tri tuyet doi trong khoang 2,9 * 10^-39 den 1,7 * 10^38 va so 0
Bien_SoThuc: REAL;
// Xau ki tu, toi da gom 255 ki tu
Bien_Chuoi: STRING;
// Mot ki tu trong bang chu cai
Bien_KyTu: CHAR;
// Mang co the chua 255 SO NGUYEN
Bien_Mang: ARRAY[1..255] OF INTEGER;
CONST // Khai bao cac hang, co the khai bao thua, nhung khong the thieu
Hang = 300;
{ HET PHAN KHAI BAO }
(* PHAN THAN - Bat buoc phai co *)
BEGIN
CLRSCR; // Lenh xoa man hinh (Su dung thu vien CRT)
// Con tro nhay xuong dong moi
WRITELN('Chao ban! Toi duoc viet bang ngon ngu lap trinh Pascal.');
// Con tro khong nhay xuong dong moi
WRITE('Hay nhap vao mot so nguyen trong khoang ''-2^15'' den ''2^15 - 1'': ');
READ(Bien_SoNguyen); // Nhan gia tri nhap vao, phan thua van con trong bo nho
WRITE('Hay nhap tiep mot so nguyen trong khoang [0] den [255]: ');
READLN(Bien_Byte); // Nhan gia tri nhap vao, phan thua se bi loai ra bo nho
WRITE(''); // Dung WRITE van hop le
WRITELN(''); // Dung WRITELN van hop le
WRITE('Gia tri ban vua nhap la: ', Bien_SoNguyen, ' va ', Bien_Byte );
GOTOXY(1,10); // Di chuyen con tro den vi tri toa do (X,Y) (Su dung thu vien CRT)
WRITELN('==================== (',
// Co the tuy y xuong dong theo mot so quy tac nhat dinh
WHEREX { Lay toa do X hien tai cua con tro (Su dung thu vien CRT) },
'x',
WHEREY { Lay toa do Y hien tai cua con tro (Su dung thu vien CRT) },
')');
WRITELN('Cau lenh dieu kien IF <Dieu_kien> THEN <Cau_lenh_dung_DK> ELSE <Cau_lenh_sai_DK>');
// Neu khong ket hop nhieu dieu kien thi co the bo qua cap dau ngoac tron ()
IF (Bien_SoNguyen > Hang) OR (Bien_SoNguyen = Hang)
THEN WRITE('Bien (', Bien_SoNguyen, ') >= Hang (', Hang, ')')
ELSE WRITE('Bien (', Bien_SoNguyen, ') < Hang (', Hang, ')');
WRITELN;
WRITELN('==================== (', WHEREX, 'x', WHEREY, ')');
WRITELN('Vong lap FOR <Gia_tri_bat_dau> TO <Gia_tri_ket_thuc> DO <Cau_lenh>');
FOR Bien_Dem := 1 TO Bien_Byte DO WRITE('->', Bien_Dem);
WRITELN;
WRITELN('==================== (', WHEREX, 'x', WHEREY, ')');
WRITELN('Vong lap WHILE <Dieu_kien> DO <Cau_lenh>');
WRITELN('Luu y: Ban co the nhan to hop phim Ctrl + C de dung ngang chuong trinh');
// Neu khong ket hop nhieu dieu kien thi co the bo qua cap dau ngoac tron ()
WHILE (Bien_Dem > 0) AND (Bien_Dem <= 9999999) DO
BEGIN // Cau lenh ghep BEGIN ... END;
Bien_Mang[Bien_Dem] := Bien_Dem * 10; // Phep gan gia tri :=
WRITE('->', Bien_Mang[Bien_Dem]);
Bien_Dem := Bien_Dem - 1;
DELAY(1000); // Tam dung chuong trinh 1 giay (Su dung thu vien CRT)
END; // END trong cau lenh ghep dung dau cham phay (;)
// Cau lenh nam tren lenh ket thuc chuong trinh (END.) khong co dau cham phay (;) van hop le
READLN // Dung READLN() van hop le
END. // Bat buoc phai co dau cham (.)
{ HET PHAN THAN }
(* ----------------------------------- LY THUYET CHUNG ------------------------------- *)
{
+ Ngoai tru du lieu dang chuoi ra, tat ca cac thanh phan con lai:
- Chi su dung cac ky tu A-Z, a-z, 0-9 va mot so ky dac biet khac
- Khong phan biet chu HOA hay chu thuong
+ Cac ten do nguoi dung tu dat:
- Khong duoc trung voi cac tu khoa
- Chi duoc phep bao gom chu cai, chu so, dau gach chan
- Khong duoc bat dau bang so
+ Cac phep toan thuong dung:
- Cong: +
- Tru: -
- Nhan: *
- Chia: /
- Chia lay phan nguyen: DIV
- Chi lay phan du: MOD
+ Cac phep so sanh:
- Bang: =
- Khong bang: <>
- Be hon: <
- Be hon hoac bang: <=
- Lon hon: >
- Lon hon hoac bang: >=
+ Cac phep so sanh ket hop thuong dung:
- Hoac: OR
- Va: AND
}