Const n=5; var a:array[1..n,1..n] of integer; i,j:integer; begin writeln('Исходная матрица:'); Randomize; for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=random(100); write(a[i,j]:4); end; writeln; end; for i:=1 to n do for j:=1 to n do if i<>j then a[i,j]:=0; writeln('Измененная матрица:'); for i:=1 to n do begin for j:=1 to n do write(a[i,j]:4); writeln; end; end.
Ленгит
Program mass; uses crt; var x:array [1..100, 1..100] of integer; i,j,n,m:integer; begin clrscr; write ('Количество строк: '); readln (n); write('Количество столбцов: '); readln (m); for i:=1 to n do for j:=1 to m do begin write('Введите элемент ' ,i,j,' матрицы:'); readln(x[i,j]); end; for i:=1 to N do begin for j:=1 to M do write (' ',x[i,j]:3); writeln; end;
for i:=1 to n do for j:=1 to m do begin if (i <> j) then x[i,j]:=0; end; writeln; for i:=1 to N do begin for j:=1 to M do write (' ',x[i,j]:3); writeln; end; readln; end.
Answers & Comments
Verified answer
Const n=5;var
a:array[1..n,1..n] of integer;
i,j:integer;
begin
writeln('Исходная матрица:');
Randomize;
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(100);
write(a[i,j]:4);
end;
writeln;
end;
for i:=1 to n do
for j:=1 to n do
if i<>j then a[i,j]:=0;
writeln('Измененная матрица:');
for i:=1 to n do
begin
for j:=1 to n do write(a[i,j]:4);
writeln;
end;
end.
Пример:
Исходная матрица:
70 77 19 40 39
28 31 64 64 98
0 67 49 82 20
43 0 16 48 56
2 34 91 25 63
Измененная матрица:
70 0 0 0 0
0 31 0 0 0
0 0 49 0 0
0 0 0 48 0
0 0 0 0 63
uses crt;
var
x:array [1..100, 1..100] of integer;
i,j,n,m:integer;
begin
clrscr;
write ('Количество строк: ');
readln (n);
write('Количество столбцов: ');
readln (m);
for i:=1 to n do
for j:=1 to m do
begin
write('Введите элемент ' ,i,j,' матрицы:');
readln(x[i,j]);
end;
for i:=1 to N do
begin
for j:=1 to M do
write (' ',x[i,j]:3);
writeln;
end;
for i:=1 to n do
for j:=1 to m do
begin
if (i <> j) then
x[i,j]:=0;
end;
writeln;
for i:=1 to N do
begin
for j:=1 to M do
write (' ',x[i,j]:3);
writeln;
end;
readln;
end.