D
D
DivineDraft2017-11-01 09:52:53
Pascal
DivineDraft, 2017-11-01 09:52:53

Why displays only part of the transformed matrix?

After entering the matrix and its transformation, only 1 column is displayed

Program zadacha_4;
const
p=100;
var
a :array [1..p,1..p] of integer; 
n ,m, b :integer;
i , j :integer;

begin
write ('m='); readln (m);
write ('n='); readln (n);
writeln ('Матрица');
for i:=1 to n do
begin
for j:=1 to n do read (a[i,j]);
end;

write('Введенная матрица ');
writeln;
for i:=1 to n do
 begin
    for j:=1 to n do 
      write (a[i,j]:2);
   writeln;
 end;

write('Преобразование матрицы ');
for i:= 1 to n do
 begin 
 for j:=1 to n do
     if a[i,j]<0 then b:=-1
     else if a[i,j]>0 then b:=1;
 writeln;
  write(b:2);
 end; 


end.

As I understand it, the error is directly in the conversion, because I am referring to only one element, most likely. Tried me values ​​- endless errors.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2017-11-01
@DivineDraft

program transformation;
var
  matrix: array of array of integer;
  n, m: integer;
  i, j: integer;
begin
  Write ('M = ');
  ReadLn (m);
  Write ('N = ');
  ReadLn (n);
  
  // Создание размера динамического массива
  SetLength(matrix, m);
  for i := 0 to m - 1 do
    SetLength(matrix[i], n);
  
  // Заполнение матрицы
  Randomize;
  for i := 0 to m - 1 do
    for j := 0 to n - 1 do
      matrix[i, j] := Random(-100, 100);
  
  // Вывод получившейся матрицы
  WriteLn();
  WriteLn('Исходная матрица:');
  WriteLn();
  for i := 0 to m - 1 do
    begin
      for j := 0 to n - 1 do
        Write(matrix[i, j]:5);
      WriteLn();
    end;
  
  // Преобразование матрицы
  WriteLn();
  WriteLn('Преобразованная матрица:');
  WriteLn();
  for i := 0 to m - 1 do
    begin
      for j := 0 to n - 1 do
        begin
          if matrix[i, j] < 0 then
            matrix[i, j] := -1;
          if matrix[i, j] > 0 then
            matrix[i, j] := 1;
          Write(matrix[i, j]:3);
        end;
      WriteLn();
    end;
end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question