
23.04.2008, 07:56
|
|
Познавший АНТИЧАТ
Регистрация: 27.04.2007
Сообщений: 1,044
С нами:
10021597
Репутация:
905
|
|
De-visible, не совсем условию соответствует
Ввод массивов выполнять в процедуре, а нахождение максимального
элемента - в функции.
Еще вариант.
Задача 1
Код:
program Zodacha_one;
const
XSize = 5;
YSize = 11;
procedure fillmassive (numel : integer; var a : array of integer);
var
i : integer;
begin
randomize;
for i := 0 to numel - 1 do
a[i] := Random (100);
end;
function getmax (numel : integer; a : array of integer) : integer;
var
i, max : integer;
begin
i := 0;
max := a[i];
while i < numel do begin
if a [i] > max then
max := a [i];
i := i + 2;
end;
getmax := max;
end;
var
x : array [1..XSize] of integer;
y : array [1..YSize] of integer;
i, max : integer;
begin
fillmassive (XSize, x);
for i := 1 to XSize do
write (x[i], ' ');
writeln;
max := getmax (XSize, x);
writeln ('Max = ', max);
fillmassive (YSize, y);
for i := 1 to YSize do
write (y[i], ' ');
writeln;
max := getmax (YSize, y);
writeln ('Max = ', max);
end.
Задача 2
Код:
program ZodachaTwo;
const
Size = 30;
type
TMassive = array [0..Size - 1] of integer;
procedure FillMassive (numel : integer; var a : TMassive);
var
i : integer;
begin
Randomize;
for i := 0 to numel - 1 do
a[i] := Random (10);
end;
function NotNullCount (numel: integer; a : TMassive) : integer;
var
i, cnt : integer;
begin
cnt := 0;
for i := 0 to numel - 1 do
if a[i] <> 0 then
cnt := cnt + 1;
NotNullCount := cnt;
end;
function DropNulls (numel : integer; a : TMassive) : TMassive;
var
i, j : integer;
t : TMassive;
begin
i := 0;
j := 0;
while i < numel do begin
if a [i] <> 0 then begin
t[j] := a [i];
j := j + 1;
end;
i := i + 1;
end;
DropNulls := t
end;
var
x, y : TMassive;
i, count : integer;
begin
FillMassive (Size, x);
for i := 0 to Size - 1 do
write (x[i], ' ');
writeln;
y := DropNulls (Size, x);
count := NotNullCount (Size, x);
for i := 0 to count - 1 do
write (y[i], ' ');
writeln;
end.
Последний раз редактировалось krypt3r; 23.04.2008 в 08:20..
|
|
|