Reputation: 1
Does anyone know how to create Matrix using array function in Pascal?
Output will be something like this:
00100 01110 11111 01110 00100
Thanks.
Edit:
This is my Code sofar:
program borlpasc;
var a:array[1..100,1..100] of integer;
i,j,n:integer;
begin write('Enter the Number N='); {Example: 5}
readln(n);
for i:=1 to n do
for j:=1 to n do
begin a[i,j]:=0;
if n mod 2 = 1 then begin
a[n div 2 + 1, j] := 1;
a[i, n div 2 + 1] := 1;
end;
end;
for i:=1 to n do
begin for j:=1 to n do write(a[i,j]:2);
writeln
end;
readln
end.
but only get this:
00100 00100 11111 00100 00100
Upvotes: 0
Views: 1896
Reputation: 212929
You don't need arrays for this, just two nested FOR loops. Here is an example which writes a grid of 1s - see if you can modify this to give the output that you need (hint: you need to add an IF statement).
program Grid;
procedure DrawGrid(nx: integer; ny: integer);
var
x, y: integer;
begin
for y := 1 to ny do
begin
for x := 1 to nx do
begin
write('1');
end;
writeln;
end;
end;
begin
DrawGrid(5, 5);
end.
Upvotes: 1