how to show the matrix in matrix form and not the numbers arranged on each other’s side?

Asked

Viewed 465 times

-4

I did but it didn’t work:

program teste;  
 uses crt;  
 var  
   iMat: array [1..3,1..3] of integer;  
   iLin, iCol: integer;  
 begin  
   write ('Digite os números da matriz: ');  
   for iLin:=1 to 3 do  
   begin  
    for iCol:=1 to 3 do  
      read (iMat[iLin,iCol]);  
   end;  
 clrscr;  
   for iLin:=1 to 3 do  
   begin  
    for iCol:=1 to 3 do  
    gotoxy (iCol,iLin); write (iMat[iLin,iCol]);  
   end;  
 readkey;  
 end.  

How to solve?

3 answers

4

Change the command write() for writeln() when writing the result.

Change:

write (iMat[iLin,iCol]);

To:

writeln (iMat[iLin,iCol]);
  • For the case of the colleague, always give new line which would display only one row, and not in table/matrix form.

2

Like this: One for row and one for column (inside).

Program HelloWorld(output);
var
  matriz: array [1..3,1..3] of integer;
  linha, coluna: integer; 
begin
  matriz[1,1] := 1;
  matriz[1,2] := 2;
  matriz[1,3] := 3;
  matriz[2,1] := 1;
  matriz[2,2] := 2;
  matriz[2,3] := 3;
  matriz[3,1] := 1;
  matriz[3,2] := 2;
  matriz[3,3] := 3;

  for linha := 1 to 3 do
      begin

        for coluna :=1 to 3 do
            begin

                write(matriz[coluna, linha]);
                write('    ');

            end;

        writeln('');

      end;


end.

1


I found the following mistake:

for iLin:=1 to 3 do
begin
for iCol:=1 to 3 do
gotoxy (iCol,iLin); write (iMat[iLin,iCol]);
end

Missed a Begin before Gotoxy.

Correcting:

program teste;  
 uses crt;  
 var  
   iMat: array [1..3,1..3] of integer;  
   iLin, iCol: integer;  
 begin  
  ClrScr;  
  write ('Digite os números da matriz: ');  
  for iLin:=1 to 3 do  
  begin  
   for iCol:=1 to 3 do  
   begin  
    Write ('(',iLin,',',iCol,')= ');  
    ReadLn (iMat[iLin,iCol]);  
   end;  
  end;  
  ClrScr;  
  for iLin:=1 to 3 do  
  begin  
   for iCol:=1 to 3 do  
   begin  
    gotoxy (iCol,iLin); write (iMat[iLin,iCol]);  
   end;  
  end;  
  readkey;  
 end.  

Browser other questions tagged

You are not signed in. Login or sign up in order to post.