//
you're reading...
00 - Chủ đề chung, Dùng cho cấp THCS, Dùng cho cấp THPT

Bài 7: Câu lệnh lặp

Pascal – Loops

http://www.tutorialspoint.com/pascal/pascal_loops.htm

Copyright © tutorialspoint.com

There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.

Programming languages provide various control structures that allow for more complicated execution paths.

A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages:

Loop ArchitecturePascal programming language provides the following types of loop constructs to handle looping requirements. Click the following links to check their details.

Loop Type Description
while-do loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.
for-do loop Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
repeat-until loop Like a while statement, except that it tests the condition at the end of the loop body.
nested loops You can use one or more loop inside any another while, for or repeat until loop.

Loop Control Statements:

Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.

Pascal supports the following control statements. Click the following links to check their details.

Control Statement Description
break statement Terminates the loop or case statement and transfers execution to the statement immediately following the loop or case statement.
continue statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
goto statement Transfers control to the labeled statement. Though it is not advised to use goto statement in your program.

Bài tập

Program Tong_bac_ba;
Var
k,n:Byte;
s:Longint;
Begin
Writeln(‘TINH TONG BAC 3 CUA N SO NGUYEN DAU TIEN’);
Writeln(‘—————————————-‘);
Write(‘-Nhap so N= ‘);
Readln(n);
S:=0;
For k:=1 To N Do
S:=S+(k*k*k);
Writeln(‘+Tong bac 3 cua ‘,n,’ so nguyen dau tien = ‘,s);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program uoc_so;
Var
i,n:Integer;
Begin
Writeln(‘TIM CAC UOC SO CUA SO NGUYEN’);
Writeln(‘—————————-‘);
Write(‘-Nhap mot so nguyen: ‘);
Readln(n);
Writeln;
Writeln(‘+Cac uoc so cua so ‘,n,’ la: ‘);
Writeln;
For i:=1 To N Do
If (n Mod i) = 0 Then
Write(i:6);
Writeln;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Tam_giac_can;
Var
cao,i,j:Byte;
Begin
Writeln(‘ TAM GIAC CAN DAC’);
Writeln(‘Chieu cao gioi han tu 1 den 22’);
Writeln(‘——————————‘);
Write(‘-Nhap chieu cao: ‘);
Readln(cao);
For i:=1 To cao Do
Begin
Write(#32:cao-i+1);
For J:=1 To (2*i-1) Do
Write(‘*’);
Writeln;
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Tong_nghich_dao;
Var
n,i:Integer;
s:Real;
Begin
Writeln(‘TINH TONG NGHICH DAO N SO NGUYEN DAU TIEN’);
Writeln(‘—————————————–‘);
Write(‘-Nhap so N= ‘);
Readln(n);
S:=0;
For i:= 1 To N Do
S:=S+(1/i);
Writeln;
Writeln(‘+Tong nghich dao cua ‘,n,’ so nguyen dau tien= ‘,S:0:2);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Tong_binh_phuong;
Var
i,n,tong:Integer;
Begin
Writeln(‘TINH TONG BINH PHUONG CAC SO LE’);
Writeln(‘ Tu 1 den N’);
Writeln(‘——————————-‘);
Write(‘-Nhap N= ‘);
Readln(n);
tong:=0;
For i:=1 To N Do
If odd(i) Then
tong:=tong+sqr(i);
Writeln;
Writeln(‘+Tong binh phuong cac so le cua ‘,n,’ so nguyen= ‘,tong);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Cuc_dai;
Var
i,n:Byte;
so,solon:Integer;
Begin
Writeln(‘TIM SO LON NHAT TRONG N SO NGUYEN’);
Writeln(‘———————————‘);
Write(‘-Muon nhap bao nhieu so: ‘);
Readln(n);
i:=1;
Write(‘-So thu ‘,i,’ = ‘);
Readln(so);
solon:=so;
For i:=2 To N Do
Begin
Write(‘-So thu ‘,i,’ = ‘);
Readln(so);
If solon < so Then
solon:=so;
End;
Writeln;
Writeln(‘+So lon nhat trong ‘,n,’ so vua nhap la so: ‘,solon);
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Tinh_giai_thua;
Var
n,i:Integer;
gt:LongInt;
Begin
Writeln(‘TINH N!’);
Writeln(‘——-‘);
Write(‘-Nhap N= ‘);
Readln(n);
gt:=1;
For i:=1 To n Do
gt:=gt*i;
Writeln;
Writeln(‘+Giai thua cua ‘,n,’ = ‘,gt);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Tam_giac_rong;
Var
cao,i:Byte;
Begin
Writeln(‘VE TAM GIAC RONG’);
Writeln(‘—————-‘);
Write(‘-Nhap chieu cao cua tam giac: ‘);
Readln(cao);
Writeln(‘*’:cao);
For i:=2 To cao-1 Do
Writeln(‘*’:cao-i+1,’*’:2*i-2);
For i:=1 To 2*cao-1 Do
Write(‘*’);
Writeln;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program In_xen_ke;
Var
dai,rong,i,j:Byte;
Begin
Writeln(‘IN XEN KE CAC DAU SAO’);
Writeln(‘——————–‘);
Write(‘-Nhap chieu dai: ‘);
Readln(dai);
Writeln(‘-Nhap chieu rong: ‘);
Readln(rong);
For i:=1 To rong Do
Begin
If i Mod 2 = 0 Then
For j:=1 To dai Div 2 Do
Write(‘ *’) {dau trang va dau sao}
Else
For j:=1 To dai Div 2 +dai Mod 2 Do
Write(‘* ‘); {dau sao va dau trang}
Writeln;
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Dem_chu;
Var
chuoi:String;
i,dem,dai:Byte;
Begin
Writeln(‘DEM CHU ”ng” TRONG CHUOI’);
Writeln(‘———————-‘);
Write(‘-Nhap mot chuoi bat ky: ‘);
Readln(chuoi);
dem:=0;
dai:=length(chuoi);
For i:=1 To dai Do
If chuoi[i]+chuoi[i+1]=’ng’ Then
inc(dem);
Writeln;
Writeln(‘Trong cau: ‘,'” ‘,chuoi,’ “‘);
Writeln(‘Co ‘,dem,’ lan xuat hien chu ”ng”’);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Phep_chia;
Var
chia,bichia,luu,thuong,du:Integer;
Begin
Writeln(‘PHEP CHIA CHI LA PHEP TRU’);
Writeln(‘————————-‘);
Write(‘-Nhap so bi chia: ‘);
Readln(bichia);
Write(‘-Nhap so chia: ‘);
Readln(chia);
luu:=bichia;
thuong:=0;
While bichia >=chia Do
Begin
bichia:=bichia-chia;
thuong:=thuong+1;
End;
du:=bichia;
Writeln;
Writeln(‘+Neu dem so ‘,luu,’ chia cho so ‘,chia,’ ket qua la: ‘);
Writeln(‘ *So thuong = ‘,thuong:6);
Writeln(‘ *So du = ‘,du:6);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program So_nguyen_to;
Var
n,i:Integer;
Begin
Writeln(‘SO VUA NHAP CO PHAI LA SO NGUYEN TO ?’);
Writeln(‘————————————-‘);
Write(‘-Nhap mot so : ‘);
Readln(n);
While n > 1 Do
Begin
i:=2;
While (n Mod i <> 0) Do
i:=i+1;
if i=n Then
Writeln(‘-So ‘,n,’ la so nguyen to’)
Else
Writeln(‘-So ‘,n,’ khong phai la so nguyen to’);
Write(‘-Nhap mot so (so 0 de ngung): ‘);
Readln(n);
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Nhap_diem;
Const
Sentinel=-1;
Var
ten:String;
diem,cao,thap,dem:Integer;
Begin
Writeln(‘XU LY DIEM THI’);
Writeln(‘————–‘);
cao:=0;
thap:=10;
dem:=0;
Write(‘-Ho va ten sinh vien: ‘);
Readln(ten);
Write(‘-Nhap diem thi: ‘);
Readln(diem);
While diem <> Sentinel Do
Begin
If diem > cao Then
cao:=diem;
If diem < thap Then
thap:=diem;
dem:=dem+1;
Write(‘-Nhap diem thi: ‘);
Readln(diem)
End;
Writeln;
Writeln(‘+Sinh vien: ‘,ten);
Writeln(‘+Da co ‘,dem,’ diem thi’);
Writeln(‘+Diem cao nhat la: ‘,cao);
Writeln(‘+Diem thap nhat la: ‘,thap);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln;
End.

Program Day_so_Fibonaci;
Var
n,j,pj,pj1,pj2:Integer;
Begin
Writeln(‘IN DAY SO FIBONACI’);
Writeln(‘——————‘);
Write(‘-Nhap so N= ‘);
Readln(n);
j:=2;
pj:=1;
pj1:=1;
While j <> n Do
Begin
pj2:=pj1;
pj1:=pj;
pj:=pj1+pj2;
j:=j+1;
End;
Writeln;
Writeln(‘+So hang thu ‘,n,’ cua day Fibonaci = ‘,pj);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Da_thuc;
Var
n,i:Integer;
x,a,dathuc: Real;
Begin
Writeln(‘TINH TRI CUA DA THUC Pn’);
Writeln(‘———————–‘);
Write(‘-Nhap so N= ‘);
Readln(n);
Write(‘-Nhap so X= ‘);
Readln(x);
i:=n;
Write(‘-Nhap tri so A’,i,’ =’);
Readln(a);
dathuc:=a;
While i <> 0 Do
Begin
i:=i-1;
Write(‘-Nhap tri so A’,i,’ =’);
Readln(a);
dathuc:=dathuc * x + a
End;
Writeln;
Writeln(‘+Tri cua da thuc = ‘,dathuc:12:10);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Luy_thua;
Var
x,n,tich,luythua:Integer;
Begin
Writeln(‘TINH TRI CUA X LUY THUA N’);
Writeln(‘————————-‘);
Write(‘-Nhap vao so X= ‘);
Readln(x);
Write(‘-Nhap vao luy thua N= ‘);
Readln(n);
tich:=1;
luythua:=1;
While luythua <= n Do
Begin
tich:=tich * x;
luythua:=luythua + 1;
End;
Writeln;
Writeln(x,’ luy thua ‘,n,’ = ‘,tich);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program cat_chuoi;
Var
chuoi,tam:String;
Begin
Writeln(‘CAT CHUOI THANH TUNG TU’);
Writeln(‘————————‘);
Write(‘-Nhap mot chuoi: ‘);
Readln(chuoi);
While chuoi <> ” Do
Begin
While chuoi[1] = #23 Do
chuoi:=copy(chuoi,2,255);
If pos(#32,chuoi) <> 0 Then
tam:=copy(chuoi,1,pos(#32,chuoi))
Else
tam:=chuoi;
Writeln(tam);
Delete(chuoi,1,length(tam));
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program thuaso;
Var
n,i:Integer;
Begin
Writeln(‘PHAN TICH N THANH TICH CAC THUA SO NGUYEN TO’);
Writeln(‘——————————————–‘);
Write(‘-Nhap so N= ‘);
Readln(n);
Repeat
i:=2;
While (n Mod i <> 0) And (i < n ) Do
i:=i + 1;
Write(i:4);
n:=n Div i;
Until n=1;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program PTB2;
Var
a,b,c,delta : Integer;
x1,x2:Real;
Begin
Writeln(‘GIAI PHUONG TRINH BAC 2’);
Writeln(‘Bat buoc he so a <> 0’);
Writeln(‘———————‘);
Repeat
Write(‘-Nhap he so a= ‘);
Readln(a);
Until a<>0;
Write(‘-Nhap he so b= ‘);
Readln(b);
Write(‘-Nhap he so c= ‘);
Readln(c);
delta:=b*b – 4*a*c;
If Delta < 0 Then
Writeln(‘+Phuong trinh vo nghiem’)
Else
If delta = 0 Then
Writeln(‘+Phuong trinh co 2 nghiem bang nhau X= ‘,-b/(2*a):6:2)
Else
Begin
Writeln(‘Phuong trinh co 2 nghiem phan biet’);
Writeln(‘+X1 = ‘,(-b+sqrt(delta))/(2*a):6:2);
Writeln(‘+X2 = ‘,(-b-sqrt(delta))/(2*a):6:2);
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program ma_ASCII;
Var
kytu:Char;
Begin
Writeln(‘MA ASCII CUA KY TU’);
Writeln(‘——————‘);
Repeat
Write(‘-Nhap mot ky tu (bam so 0 de ket thuc) ‘);
Readln(kytu);
Writeln(‘+Ky tu ‘,kytu,’ co ma ASCII = ‘,ord(kytu));
Writeln;
Until kytu=’0’;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program May_tinh_tay;
Var
so1,so2,kq:Real;
toantu,tiep:Char;
thuchien:Boolean;
Begin
Writeln(‘ MAY TINH TAY’);
Writeln(‘Thuc hien 4 phep tinh so hoc’);
Writeln(‘—————————-‘);
Repeat
Write(‘-Bam so: ‘);
Readln(so1);
Write(‘-Phep toan(+,-,*,/): ‘);
Readln(toantu);
Write(‘-Bam so: ‘);
Readln(so2);
thuchien:=True;
Case toantu Of
‘+’ :kq:=so1+so2;
‘-‘ :kq:=so1-so2;
‘*’ :kq:=so1*so2;
‘/’ :If so2 <> 0 Then
kq:=so1/so2
Else
thuchien:=False;
Else thuchien:=False;
End;
If thuchien Then
Writeln(‘+Ket qua = ‘,kq:6:2)
Else
Writeln(‘+Khong lam duoc’);
Writeln;
Write(‘-Thuc hien tiep khong ? (C/K) ‘);
Readln(tiep);
Until Upcase(tiep) = ‘K’;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program So_nguyen_to;
Var
n,i:Integer;
Begin
Writeln(‘SO NGUYEN TO’);
Writeln(‘————‘);
Repeat
Write(‘-Nhap so N (bam so 0 de ngung)= ‘);
Readln(n);
Writeln;
i:=1;
If n > 1 Then
Repeat
i:= i +1;
Until (n Mod i = 0);
If i= n Then
Writeln(‘ +So ‘,n,’ la so nguyen to’)
Else
Writeln(‘ +So ‘,n, ‘ khong phai la so nguyen to’);
Writeln;
Until n=0;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln;
End.

Program Doi_so_he_2;
Var
n,so:Integer;
tiep:Char;
Begin
Writeln(‘DOI SO HE 10 SANG HE 2’);
Writeln(‘———————-‘);
Repeat
Write(‘-Nhap so nguyen he 10: ‘);
Readln(so);
n:=16384; {Gan n= 2 luy thua 14}
Writeln;
Write(‘+So he 2 la ‘);
Repeat
Write(so Div n);
so:=so – n * (so Div n);
n:= n Div 2;
Until n=0;
Writeln;
Write(‘-Tiep tuc nua khong (C/K) ‘);
Readln(tiep);
Until Upcase(tiep)=’K’;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Doi_he_16;
Var
n,so,chuso:Integer;
tiep:Char;
Begin
Writeln(‘DOI SO HE 10 SANG HE 16’);
Writeln(‘———————–‘);
Repeat
Write(‘-Nhap so he 10 = ‘);
Readln(so);
n:=4096; {16 luy thua 3}
Write(‘+Ky so he 16= ‘);
Repeat
chuso:=so Div n;
Case chuso Of
0..9:Write(chuso);
10 .. 15:Write(chr(chuso + 55));
End;
so:=so- n*(so Div n);
n:=n Div 16;
Until n=0;
Writeln;
Write(‘-Co thuc hien tiep khong ? (C/K) ‘);
Readln(tiep);
Until Upcase(tiep)=’K’;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Uoc_so_chung_Boi_so_chung;
Var
so1,so2:Word;
p:LongInt;
tiep:Char;
Begin
Writeln(‘TINH UOC SO CHUNG LON NHAT, BOI SO CHUNG NHO NHAT’);
Writeln(‘ Su dung vong lap Repeat… Until’);
Writeln(‘————————————————-‘);
Repeat
Writeln;
Write(‘-Nhap so thu nhat: ‘);
Readln(so1);
Write(‘-Nhap so thu hai : ‘);
Readln(so2);
p:=so1 * so2;
Write(‘+Uoc so chung lon nhat cua ‘,so1,’ va ‘,so2,’ la: ‘);
Repeat
if so1 > so2 Then
so1:=so1 – so2
Else
so2:=so2 – so1;
Until so1=so2;
Writeln(so1);
Writeln;
Writeln(‘+Boi so chung nho nhat: ‘,P Div so1);
Writeln;
Write(‘-Co tiep tuc nua khong ? (C/K) ‘);
Readln(tiep);
Until Upcase(tiep)=’K’;
Writeln;
Writeln(‘ Bam phim de ket thuc ‘);
Readln
End.

Program Co_My;
Var
i,j,dai1,dai2,rong1,rong2:Byte;
Begin
Writeln(‘IN LA CO NUOC MY RA MAN HINH’);
Writeln(‘—————————–‘);
Write(‘-Nhap chieu rong_1: ‘);
Readln(rong1);
Write(‘-Nhap chieu rong_2: ‘);
Readln(rong2);
Write(‘-Nhap chieu dai_1: ‘);
Readln(dai1);
Write(‘-Nhap chieu dai_2: ‘);
Readln(dai2);
For i:=1 To rong1 Do
Begin
If odd(i) Then
Begin
For j:=1 To (dai1 Div 2) Do
Write(‘*’,’ ‘);
If odd(dai1) Then
Write(‘ ‘,’*’);
End
Else
Begin
For j:=1 To (dai1 Div 2) Do
Write(‘ ‘,’*’);
If odd(dai1) Then
Write(‘ ‘);
End;
For j:=1 to dai2 Do
Write(‘=’);
Writeln;
End;
For i:=1 To rong2 Do
Begin
For j:=1 To dai1+dai2 Do
Write(‘=’);
Writeln;
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Dan_so;
Var
i:Byte;
sodan:LongInt;
Begin
Writeln(‘TINH DAN SO SAU 5 NAM’);
Writeln(‘———————‘);
sodan:=5000000;
Writeln(‘-So dan hien nay = ‘,sodan);
Writeln(‘-Ty le tang dan so hang nam = 1.5%’);
Writeln;
Writeln(‘So dan tang tung nam trong 5 nam toi la:’);
For i:=1 To 5 Do
Begin
sodan:=round(sodan * 1.015);
Writeln(‘-Nam thu ‘,i,’ so dan la: ‘,sodan,’ nguoi’);
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Tim_cac_so_nguyen;
Var
a,b,c,d:Integer;
khac:Boolean;
Begin
Writeln(‘TIM CAC SO NGUYEN KHAC NHAU’);
Writeln(‘—————————‘);
For a:=2 To 10 Do
For b:=2 To 10 do
For c:=2 To 10 Do
For d:=2 To 10 Do
Begin
khac:=(a<>b) And (a<>c) And (a<>d)
And (b<>c) And (b<>d) And (c<>d);
If khac And (a*d*d=b*c*c*c) Then
Writeln(a,’*’,d,’*’,d,’ = ‘,b,’*’,c,’*’,c,’*’,c);
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program To_hop_chp_k_cua_N;
Var
i,k,n:Integer;
c:Real;
Begin
Writeln(‘TINH TO HOP CHAP k CUA N’);
Writeln(‘ Voi k <= N’); Writeln(‘————————‘); Write(‘-Nhap so N= ‘); Readln(n); Write(‘-Nhap so phan tu k= ‘); Readln(k); If k > N Then
Writeln(‘+Vi k lon hon N nen khong tinh duoc’)
Else
Begin
c:=1;
For i:=1 To k Do
c:=c*(n-k+i)/i;
Writeln(‘+To hop chap ‘,k,’ cua ‘,n,’ la: ‘,c:2:2);
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Tram_trau;
Var
dung,nam,gia,co,trau:Integer;
Begin
Writeln(‘BAI TOAN CO DIEN’);
Writeln(‘Tram trau tram co’);
Writeln(‘Trau dung an 5’);
Writeln(‘Trau nam an 3’);
Writeln(‘Ba trau gia an 1’);
Writeln(‘—————-‘);
Writeln(‘ Bai toan nay co cac loi giai sau’);
For dung:=0 To 20 Do
For nam:=0 To 33-dung Do
For gia:=0 To (100-(dung+nam)) Do
Begin
co:=5*dung+3*nam+(gia Div 3);
trau:=dung+nam+gia;
If (gia Mod 3 =0) And (trau=100) And ( co=100) Then
Writeln(‘-Trau dung ‘,dung,’ con, -Trau nam ‘,nam,’ con, -Trau gia ‘,gia,’ con’);
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program ga_cho;
Var
x,y,n:Integer;
Begin
n:=1;
Writeln(‘* CAC LOI GIAI BAI TOAN CO DIEN GA,CHO’);
Writeln(‘———————————-‘);
For x:=1 To 36 Do
For y:=1 To (36-x) Do
If ((x*2)+(y*4) =100) then {and ((x+y) =36) Then}
Begin
Writeln(‘ * Loi giai thu : ‘,n:3);
Write(‘- Ga = ‘,x:2,’ con = ‘,(x*2):2,’ chan ‘);
Write(‘- Cho = ‘,y:2,’ con = ‘,(y*4):2,’ chan ‘);
If x+y Writeln(‘Ga+Cho= ‘,x+y:2,’ con,khong dung’)
Else If x+y=36 Then
Writeln(‘Ga+Cho= ‘,x+y:2,’ con,loi giai dung’);
n:=n+1;
End;
Writeln(‘ * Tong cong co: ‘,(n-1):3,’ loi giai’);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Bang_cuu_chuong;
Var
i,j:Integer;
Begin
Writeln(‘ BANG CUU CHUONG’);
Writeln(‘ —————‘);
For i:=1 To 9 Do
For j:=1 To 5 Do
Write(j:2,’ lan ‘,i:2,’ = ‘,j*i:2,’ ‘);
Writeln;
Writeln(‘ —————————————————‘);
For i:=1 To 9 Do
For j:=6 To 10 Do
Write(j:2,’ lan ‘,i:2,’ = ‘,j*i:2,’ ‘);
Writeln(‘ —————————————————‘);
Writeln;
Write(‘ Bam phim de ket thuc’);
Readln
End.

Program gap_giay;
Var
day:Real;
solan:Integer;
Begin
Writeln(‘GAP GIAY CO DO DAY 1 MET’);
Writeln(‘————————‘);
day:=0.1;
solan:=0;
While day < 1000 Do
Begin
day:=day * 2;
solan:=solan+1;
End;
Writeln;
Writeln(‘+Phai gap toi: ‘,solan,’ lan’);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Tim_so_nguyen_to;
Var
n,i,j:Integer;
nguyento:Boolean;
Begin
Writeln(‘TIM CAC SO NGUYEN TO TU 2 DEN N’);
Writeln(‘——————————-‘);
Write(‘-Nhap so N= ‘);
Readln(n);
For i:=2 To n Do
Begin
nguyento:=True;
j:=2;
While nguyento And (j <i) Do
Begin
If (i Mod j)=0 Then
nguyento:=False;
j:=j+1;
End;
If nguyento Then
Write(i:4);
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Doi_bong;
Var
thang,tong,cauthu,i:Integer;
tb:Real;
tiep:Char;
Begin
Writeln(‘THANH TICH CUA DOI BONG’);
Writeln(‘———————–‘);
i:=1;
cauthu:=0;
tong:=0;
tiep:=’c’;
While Upcase(tiep)=’C’ Do
Begin
Write(‘-Cau thu thu ‘,i,’ co so ban thang: ‘);
Readln(thang);
i:=i+1;
tong:=tong+thang;
cauthu:=cauthu+1;
Write(‘-Nhap tiep nua khong (c/k) ‘);
Readln(tiep);
End;
tb:=tong/cauthu;
Writeln;
Writeln(‘+So cau thu cua Doi= ‘,cauthu);
Writeln(‘+So ban thang trung binh cua Doi= ‘,tb:5:1);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program In_Chu_hoa;
Var
kytu:Char;
Begin
Writeln(‘IN CHU HOA’);
Writeln(‘———-‘);
Write(‘-Nhap ky tu: ‘);
Readln(kytu);
While (‘A’ <= kytu) And (kytu <=’Z’) Do
Begin
Writeln(kytu);
Write(‘-Nhap ky tu: ‘);
Readln(kytu);
End;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Uoc_so_Boi_so_chung;
Var
a,b:Word;
p:LongInt;
Begin
Writeln(‘UOC SO CHUNG LON NHAT, BOI SO CHUNG NHO NHAT’);
Writeln(‘——————————————–‘);
Write(‘-Nhap so thu nhat a= ‘);
Readln(a);
Write(‘-Nhap so thu hai b= ‘);
Readln(b);
p:=a * b;
Write(‘+Uoc so chung lon nhat cua ‘,a,’ va ‘,b,’ la: ‘);
While a <> b Do
Begin
If a > b Then
a:=a – b
Else
b:=b-a
End;
Writeln(a);
Writeln;
Writeln(‘+Boi so chung nho nhat cua chung la: ‘,p Div a);
writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Doan_so;
Var
tren,duoi,giua:Integer;
chon:Word;
Begin
tren:=100;
duoi:=1;
While duoi < tren Do
Begin
Writeln(‘DOAN SO BAN DANG NGHI TRONG DAU’);
Writeln(‘——————————-‘);
giua:=(tren+duoi) Div 2;
Writeln(‘-So cua ban Ty: ‘,giua);
Writeln(‘-Neu go so 0 se ngung’);
Writeln(‘-Neu ban Ty noi so ‘,giua,’ nho hon thi ban Teo go 1 ‘);
Write(‘-Neu ban Ty noi so ‘,giua,’ lon hon thi ban Teo go 2 ‘);
Readln(chon);
If chon = 0 Then
exit;
If chon = 1 Then
duoi:=giua
Else
tren:=giua
End;
Readln
End.

Program Nhap_ky_tu;
Var
kytu:Char;
thoat:Boolean;
Begin
Writeln(‘NHAP VA IN KY TU, KY SO RA MAN HINH’);
Writeln(‘———————————–‘);
thoat:=False;
Repeat
Write(‘-Nhap ky tu (bam ky tu dieu khien) de ket thuc: ‘);
Readln(kytu);
Case kytu Of
‘A’..’Z’:Writeln(kytu,’ ,chu thuong tuong ung la: ‘,chr(ord(kytu)+32));
‘a’..’z’:Writeln(kytu,’ ,chu hoa tuong ung la: ‘,chr(ord(kytu)-32));
‘0’..’9′:Writeln(kytu);
Else thoat:=True;
End;
Until thoat;
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Program Gui_tiet_kiem;
Var
x,y:Real;
thang:Word;
tiep:Char;
Begin
Writeln(‘GUI TIEN TIET KIEM’);
Writeln(‘——————‘);
Repeat
Write(‘-So tien hien co: ‘);
Readln(x);
Write(‘-So tien muon co: ‘);
Readln(y);
thang:=0;
Repeat
inc(thang);
x:= x *1.015;
Until x >=y;
Writeln(‘+Thoi gian can gui: ‘,thang,’ thang’);
Writeln;
Write(‘-Co tiep tuc nua khong (C/K) ‘);
Readln(tiep);
Until Upcase(tiep)=’K’;
End.

Program Nhap_diem;
Var
toan,tong,tb:Real;
hs:Byte;
tiep:Char;
Begin
Writeln(‘NHAP DIEM MON TOAN VA TINH DIEM TRUNG BINH CUA LOP’);
Writeln(‘————————————————–‘);
hs:=1;
tong:=0;
tiep:=’C’;
Repeat
Writeln(‘-Hoc sinh thu: ‘,hs);
Write(‘-Diem mon Toan : ‘);
Readln(toan);
tong:=tong+toan;
hs:=hs+1;
Write(‘ -Nhap nua khong (C/K) ‘);
Readln(tiep);
Until Upcase(tiep)=’K’;
hs:=hs-1;
tb:=tong/hs;
Writeln(‘+Tong so diem = ‘,tong:5:2,’ diem’);
Writeln(‘+Tong so ca lop co = ‘,hs,’ hoc sinh’);
Writeln(‘+Diem trung binh cua mon Toan= ‘,tb:5:2,’ diem’);
Writeln;
Writeln(‘ Bam phim de ket thuc’);
Readln
End.

Advertisements

About pascalteacher

Trang thông tin Toán học và Tin học

Thảo luận

Không có bình luận

Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s

Các tác giả

Chuyên mục

Tháng Mười 2014
H B T N S B C
« Th11   Th11 »
 12345
6789101112
13141516171819
20212223242526
2728293031  

NCT Computer

Flickr Photos

Pine Martens

King

Alfred Nicholas Memorial Gardens 2017-03-18 (5D_32A6187)

More Photos

Thống kê

  • 115,063 lượt xem

pascalteacher.nct@gmail.com


Trang huấn luyện học sinh giỏi Tin học

%d bloggers like this: