Const n=10; m=7; var j,i,i_max,s,max:integer; a:array[1..n,1..m]of integer; begin for i:=1 to n do begin writeln; s:=0;i_max:=i;max:=-32768; for j:=1 to m do begin a[i,j]:=random(100)-50; write(a[i,j]:4); s:=s+a[i,j]; end; writeln('i: ',i,' ',s); if s>max then begin i_max:=i; max:=s; end; end; writeln; writeln(i_max,' s: ',max); end.
procedure GetMax (A: array of Integer; var imax: Integer);
var
i: Integer;
begin
imax := Low (A);
for i := Low (A) to High (A) do
if A [i] > A [imax] then
imax := i;
end;
procedure GetMin (A: array of Integer; var imin: Integer);
var
i: Integer;
begin
imin := Low (A);
for i := Low (A) to High (A) do
if A [i] < A [imin] then
imin := i;
end;
procedure Repl (var A: array of Integer; OldValue, NewValue: Integer);
var
i: Integer;
begin
for i := Low (A) to High (A) do
if A [i] > OldValue then
A [i] := NewValue;
end;
var
A: array [0..49] of Integer;
i, imax, imin: Integer;
begin
Randomize;
for i := Low (A) to High (A) do begin
A [i] := Random (21) - 10;
Write (A [i] :3, ' ');
end;
WriteLn;
GetMax (A, imax);
WriteLn ('Максимальное значение = ', A [imax]);
GetMin (A, imin);
WriteLn ('Минимальное значение = ', A [imin]);
Repl (A, 1, 0);
WriteLn ('Замена >1 на 0');
for i := Low (A) to High (A) do
Write (A [i] :3, ' ');
ReadLn;
end.
задача 2
program ProcArray1;
procedure Multi (A: array of Integer; var Prod: LongInt);
var
i: Integer;
begin
Prod := 1;
for i := Low (A) to High (A) do
Prod := Prod * A [i];
end;
procedure Repl (var A: array of Integer; OldValue, NewValue: Integer);
var
i: Integer;
begin
for i := Low (A) to High (A) do
if A [i] > OldValue then
A [i] := NewValue;
end;
var
A: array [0..29] of Integer;
i: Integer;
p: LongInt;
begin
Randomize;
for i := Low (A) to High (A) do begin
A [i] := Random (3) + 1;
Write (A [i] :3, ' ');
end;
WriteLn;
Multi (A, p);
WriteLn ('Произведение = ', p);
Repl (A, 5, 1);
WriteLn ('Замена >5 на 1');
for i := Low (A) to High (A) do
Write (A [i] :3, ' ');
ReadLn;
end.
Объяснение:
Во задаче №2 при заполнении массива значениями больше 5 начинает возникать переполнение LongInt из за чего значение произведения становится отрицательным
n=10; m=7;
var
j,i,i_max,s,max:integer;
a:array[1..n,1..m]of integer;
begin
for i:=1 to n do
begin
writeln; s:=0;i_max:=i;max:=-32768;
for j:=1 to m do
begin
a[i,j]:=random(100)-50;
write(a[i,j]:4);
s:=s+a[i,j];
end;
writeln('i: ',i,' ',s);
if s>max then
begin
i_max:=i;
max:=s;
end;
end;
writeln;
writeln(i_max,' s: ',max);
end.
задача 1
program ProcArray;
procedure GetMax (A: array of Integer; var imax: Integer);
var
i: Integer;
begin
imax := Low (A);
for i := Low (A) to High (A) do
if A [i] > A [imax] then
imax := i;
end;
procedure GetMin (A: array of Integer; var imin: Integer);
var
i: Integer;
begin
imin := Low (A);
for i := Low (A) to High (A) do
if A [i] < A [imin] then
imin := i;
end;
procedure Repl (var A: array of Integer; OldValue, NewValue: Integer);
var
i: Integer;
begin
for i := Low (A) to High (A) do
if A [i] > OldValue then
A [i] := NewValue;
end;
var
A: array [0..49] of Integer;
i, imax, imin: Integer;
begin
Randomize;
for i := Low (A) to High (A) do begin
A [i] := Random (21) - 10;
Write (A [i] :3, ' ');
end;
WriteLn;
GetMax (A, imax);
WriteLn ('Максимальное значение = ', A [imax]);
GetMin (A, imin);
WriteLn ('Минимальное значение = ', A [imin]);
Repl (A, 1, 0);
WriteLn ('Замена >1 на 0');
for i := Low (A) to High (A) do
Write (A [i] :3, ' ');
ReadLn;
end.
задача 2
program ProcArray1;
procedure Multi (A: array of Integer; var Prod: LongInt);
var
i: Integer;
begin
Prod := 1;
for i := Low (A) to High (A) do
Prod := Prod * A [i];
end;
procedure Repl (var A: array of Integer; OldValue, NewValue: Integer);
var
i: Integer;
begin
for i := Low (A) to High (A) do
if A [i] > OldValue then
A [i] := NewValue;
end;
var
A: array [0..29] of Integer;
i: Integer;
p: LongInt;
begin
Randomize;
for i := Low (A) to High (A) do begin
A [i] := Random (3) + 1;
Write (A [i] :3, ' ');
end;
WriteLn;
Multi (A, p);
WriteLn ('Произведение = ', p);
Repl (A, 5, 1);
WriteLn ('Замена >5 на 1');
for i := Low (A) to High (A) do
Write (A [i] :3, ' ');
ReadLn;
end.
Объяснение:
Во задаче №2 при заполнении массива значениями больше 5 начинает возникать переполнение LongInt из за чего значение произведения становится отрицательным