mang mot chieu
Unit MMC;
Interface
var i,n,j:integer; a:array[1..20] of integer;
procedure Nhap;
procedure Hienthi;
function Max(i,n:integer) : integer;
function Min(i,n:integer) : integer;
procedure SXtangdan;
procedure SXgiamdan;
Implementation
Procedure Nhap;
Begin
writeln('Nhap vao danh sach so nguyen');
write('Nhap vao so phan tu cua mang: ');readln(n);
for i:=1 to n do
begin
write('a[',i,']=');
readln(a[i]);
end;
end;
Procedure Hienthi;
Begin
write('Danh sach so nguyen da nhap la:' );
for i:=1 to n do write(a[i]:3);
end;
Function Max(i,n:integer):integer;
Var SLN:integer;
Begin
SLN:=a[1];
for i:=1 to n do
if a[i]>SLN then SLN:=a[i];
Max:=SLN;
end;
Function Min(i,n:integer):integer;
Var SNN:integer;
Begin
SNN:=a[1];
for i:=1 to n do
if a[i]<SNN then SNN:=a[i];
Min:=SNN;
end;
Procedure SXtangdan;
var t:integer;
Begin
for i:=1 to n do
for j:=i+1 to n do
if a[j]<a[i] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
write('Day so theo thu tu tang dan la: ');
for i:=1 to n do write(a[i]:4);
end;
Procedure SXgiamdan;
var t:integer;
Begin
for i:=1 to n do
for j:=i+1 to n do
if a[j]>a[i] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
write('Day so theo thu tu giam dan la: ');
for i:=1 to n do write(a[i]:4);
end;
End.
program vd;
uses crt,mmc;
Begin
clrscr;
Nhap;
Hienthi;
writeln;
SXtangdan;
writeln;
write('Phan tu lon nhat cua mang la: ',max(i,n));
writeln;
write('Phan tu nho nhat cua mang la: ',min(i,n));
readln;
end.
Bạn đang đọc truyện trên: Truyen247.Pro