Display the matrix A (dimension NxN, enter numbers randomly) in the I quarter - 1, in the II quarter - 2, in the III quarter - 3, in the IV quarter - 4. N-even, for example:

111222 111222 111222 333444 333444 333444

Here is the code: program Project2;

 {$APPTYPE CONSOLE} uses SysUtils; var i,j,k,n:integer; a:array[1..100] of array [1..100] of integer; begin write('please enter n: '); readln(n); writeln; k:=1; for j:=1 to n do begin for i:=1 to n do begin a[i,j]:=k; if (i mod 2)=0 then inc(k); if a[i,j]<10 then write(' '); write(a[i,j],' '); end; writeln; end; readln; end. 
  • one
    Do not forget to issue a code in a question properly. - Nofate
  • "Randomly enter numbers", - how is it, how is it? - BuilderC
  • this is not superfluous from this task - Andrei1993
  • By the way, why instead of a: array [1..100] of array [1..100] of integer; don't just write a: array [1..100, 1..100] of integer; - Nofate

1 answer 1

Your mistake is that you increase k every time i increases by 2.

 if (i mod 2) = 0 then inc(k); 

And here's what you need:

 {$APPTYPE CONSOLE} uses SysUtils; var i, j, d, n:integer; a:array[0..100] of array [0..100] of integer; begin write('please enter n: '); readln(n); d := n div 2; writeln; for j := 0 to n - 1 do begin for i := 0 to n - 1 do begin a[i, j] := (i div d) + (j div d) * 2 + 1; if a[i, j] < 10 then write(' '); write(a[i, j], ' '); end; writeln; end; readln; end.