Смекни!
smekni.com

Процедуры и функции (стр. 2 из 2)


3.2. Текст программы

PROGRAM SEM2;

uses crt;

const Nmax=10;

Mmax=10;

Kmax=100;

type matr=array[1..Nmax,1..Mmax] of integer;

vector=array[1..Kmax] of integer;

var A:matr;

C:vector;

Na,i,j,Ma,Nc,k,M:integer;

Procedure Vvod(var x:matr; var Nx,Mx:integer; P:char);

begin

clrscr;

write('Vvedite N: ');

read(Nx);

writeln;

write('Vvedite M: ');

read(Mx);

writeln;

for i:=1 to Nx do

for j:=1 to Mx do begin

write(P,'[',i,',',j,']=');

read(x[i,j]);

end;

end;

Procedure Sozd(var x:matr; Nx,Mx:integer);

begin

Nc:=0;

k:=1;

i:=1;

repeat

j:=1;

repeat

if (x[i,j]<>0) then begin

c[k]:=x[i,j];

Nc:=Nc+1;

k:=k+1;

end;

j:=j+1;

until j>Mx;

i:=i+1;

until i>Nx;

end;

Function Modul(var x:vector; Nx:integer):integer;

begin

M:=0;

for k:=1 to Nx do M:=M+x[k];

M:=ABS(M);

Modul:=M;

end;

Procedure Vivod(var x:vector; Nx:integer; P:char);

begin

writeln;

writeln('Vector ',P,':');

writeln;

k:=1;

repeat

write(x[k],' ');

k:=k+1;

until k>Nx;

writeln;

end;

begin

vvod(a,na,ma,'A');

Sozd(a,na,ma);

M:=Modul(c,nc);

vivod(c,nc,'C');

writeln;

writeln('MODUL= ',M);

end.

4.2. Тестовый пример и результат

N=2 M=3

-4 2 0

0 4 –6

Vector:

-4 2 4 -6

Modul=4