Matrix with two diagonals: Difference between revisions

Added Action!
(Added PL/M)
(Added Action!)
Line 41:
0 1 0 0 0 1 0
1 0 0 0 0 0 1
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">
;;; draw a matrix with 1s on the diagonals and 0s elsewhere
 
;;; draws a matrix with height and width = n with 1s on the diagonals
PROC drawDiagonals( INT n )
CARD i, j, r
r = n
FOR i = 1 TO n DO
FOR j = 1 TO n DO
Put(' )
IF j = i OR j = r THEN Put('1) ELSE Put('0) FI
OD
PutE()
r ==- 1
OD
RETURN
 
PROC Main()
drawDiagonals( 6 )
PutE()
drawDiagonals( 7 )
RETURN
</syntaxhighlight>
{{out}}
<pre>
1 0 0 0 0 1
0 1 0 0 1 0
0 0 1 1 0 0
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 0 0 1
 
1 0 0 0 0 0 1
0 1 0 0 0 1 0
0 0 1 0 1 0 0
0 0 0 1 0 0 0
0 0 1 0 1 0 0
0 1 0 0 0 1 0
1 0 0 0 0 0 1
</pre>
 
3,022

edits