[ Pascal ] Ví dụ về cấu trúc điều khiển và mảng 1 chiều
{
Vi du 1:
In ra man hinh tat ca so nguyen duong gom 4 chu so, sao cho tong cac chu so >=10.
}
uses crt;
var a,dv,ch,tr,ng:integer; {dv: don vi, ch: chuc, tr: tram, ng: nghin}
Begin
clrscr;
writeln(' * IN DAY SO: ');
for a:=1000 to 9999 do
begin
dv:=a mod 10;
ch:=(a div 10) mod 10;
tr:=(a div 100) mod 10;
ng:=a div 1000;
if (dv+ch+tr+ng >=10) then
write(a,'; ');
end;
readln;
End.
{----------------------------------------------------------------}
{
Vi du 2:
Nhap vao day so nguyen gom n so (1<n<100). Dem so nguyen to co trong day so vua nhap
}
uses crt;
var
a:array[1..100] of integer;
n,d,i,j,kt : integer; {d: chua ket qua dem, kt: kiem tra}
Begin
clrscr;
{Nhap n}
writeln(' * Nhap so phan tu: ');
repeat
begin
write(' n= '); readln(n);
if ((n<=1) or (n >=100)) then
writeln(' Nhap lai n!');
end
until ((n>1) and (n<100));
{Nhap day so}
for i:=1 to n do
begin
write(' a[',i,']= ');
readln(a[i]);
end;
{In day vua nhap}
writeln(' Day vua nhap: ');
for i:=1 to n do
write(a[i],'; ');
{Dem so nguyen to}
d:=0;
for i:=0 to n do
begin
{kiem tra xem a[i] co phai so nguye to khong}
if (a[i]>0 ) then
begin
kt:=0;
for j:=2 to a[i]-1 do
if (a[i] mod j=0) then
kt:=1;
if (kt=0) then
d:=d+1;
end;
end;
writeln(' => Co ',d,' so nguyen to trong day');
readln;
End.