Модуль matrica.pas
unit Matrica;
interface
const nmax=20;
type mas=array[1..nmax,1..nmax] of integer;
Procedure Vvod(var x,y:byte;var mt:mas);
Procedure Vyvod(x,y:byte;var mt:mas);
function MaxEl(x,y:byte;mt:mas):integer;
function MinEl(x,y:byte;mt:mas):integer;
implementation
Procedure Vvod(var x,y:byte;var mt:mas);
var i,j:integer;
Begin
repeat
write('Vvedite kolichestvo strok:');
readln(x);
write('Vvedite kolichestvo stolbcov:');
readln(y);
until (x>0)and(x<=nmax)and(y>0)and(y<=nmax);
writeln('Vvedite ',x*y,' elementov matricy:');
for i:=1 to x do
for j:=1 to y do
begin
write('el[',i,',',j,']=');
readln(mt[i,j]);
end;
end;
Procedure Vyvod(x,y:byte;var mt:mas);
var i,j:integer;
begin
for i:=1 to x do
begin
for j:=1 to y do
write(mt[i,j]:4);
writeln;
end;
end;
function MaxEl(x,y:byte;mt:mas):integer;
var i,j:byte;
max:integer;
begin
max:=mt[1,1];
for i:=1 to x do
for j:=1 to y do
if mt[i,j]>max then max:=mt[i,j];
MaxEl:=max;
end;
function MinEl(x,y:byte;mt:mas):integer;
var i,j:byte;
min:integer;
begin
min:=mt[1,1];
for i:=1 to x do
for j:=1 to y do
if mt[i,j]<min then min:=mt[i,j];
MinEl:=min;
end;
end.
Программа
uses crt,Matrica;
var a:mas;
n,m:byte;
begin
clrscr;
Vvod(n,m,a);
clrscr;
writeln('Matrica A:');
Vyvod(n,m,a);
writeln('Minimalnyj element matricy=',MinEl(n,m,a));
writeln('Maximalnyj element matricy=',MaxEl(n,m,a));
readln
end.