Паскаль.напишите в полной форме.ввести двумерный массив a nxm . каждый четный элемент массива нацело разделить на два. массив вывести до и после преобразования.
Const n=3; m=4; var a:array[1..n,1..m] of integer; i,j:integer; begin for i:=1 to n do for j:=1 to m do begin write('a[',i,',',j,'] ='); readln(a[i,j]); end; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to m do write(a[i,j]:4); writeln; end; for i:=1 to n do for j:=1 to m do if a[i,j] mod 2 = 0 then a[i,j]:=a[i,j] div 2; writeln('Полученный массив:'); for i:=1 to n do begin for j:=1 to m do write(a[i,j]:4); writeln; end; end.
var ar: array of array of integer; n, m, i, j: integer;
begin read(n, m); setlength(ar, n); for i := 0 to n - 1 do setlength(ar[i], m); writeln('Enter matrix:'); for i := 0 to n - 1 do begin writeln; for j := 0 to m - 1 do read(ar[i, j]); end; writeln; writeln('First matrix:'); for i := 0 to n - 1 do begin writeln; for j := 0 to m - 1 do write(ar[i, j]:4); end; writeln; writeln('Final matrix:'); for i := 0 to n - 1 do begin writeln; for j := 0 to m - 1 do begin if ar[i, j] mod 2 = 0 then ar[i, j] := ar[i, j] div 2; write(ar[i, j]:4); end; end; end.
var a:array[1..n,1..m] of integer;
i,j:integer;
begin
for i:=1 to n do
for j:=1 to m do
begin
write('a[',i,',',j,'] =');
readln(a[i,j]);
end;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to m do write(a[i,j]:4);
writeln;
end;
for i:=1 to n do
for j:=1 to m do
if a[i,j] mod 2 = 0 then a[i,j]:=a[i,j] div 2;
writeln('Полученный массив:');
for i:=1 to n do
begin
for j:=1 to m do write(a[i,j]:4);
writeln;
end;
end.
Пример:
a[1,1] =45
a[1,2] =32
a[1,3] =76
a[1,4] =12
a[2,1] =85
a[2,2] =19
a[2,3] =35
a[2,4] =74
a[3,1] =65
a[3,2] =37
a[3,3] =83
a[3,4] =67
Исходный массив:
45 32 76 12
85 19 35 74
65 37 83 67
Полученный массив:
45 16 38 6
85 19 35 37
65 37 83 67
var
ar: array of array of integer;
n, m, i, j: integer;
begin
read(n, m);
setlength(ar, n);
for i := 0 to n - 1 do
setlength(ar[i], m);
writeln('Enter matrix:');
for i := 0 to n - 1 do
begin
writeln;
for j := 0 to m - 1 do
read(ar[i, j]);
end;
writeln;
writeln('First matrix:');
for i := 0 to n - 1 do
begin
writeln;
for j := 0 to m - 1 do
write(ar[i, j]:4);
end;
writeln;
writeln('Final matrix:');
for i := 0 to n - 1 do
begin
writeln;
for j := 0 to m - 1 do
begin
if ar[i, j] mod 2 = 0 then ar[i, j] := ar[i, j] div 2;
write(ar[i, j]:4);
end;
end;
end.
Пример ввода:
2
3
Enter matrix:
1
2
3
4
5
6
Пример вывода:
First matrix:
1 2 3
4 5 6
Final matrix:
1 1 3
2 5 3