Matrix with two diagonals: Difference between revisions

Add Draco
(Add Draco)
Line 502:
1 0 0 0 0 0 0 0 1
</pre>
 
=={{header|Draco}}==
<lang draco>proc setDiagonals([*,*] byte matrix) void:
word x, y, width, height;
width := dim(matrix, 1);
height := dim(matrix, 2);
for x from 0 upto width-1 do
for y from 0 upto height-1 do
matrix[x,y] :=
if x = y or width - x - 1 = y
then 1
else 0
fi
od
od
corp
 
proc printMatrix([*,*] byte matrix) void:
word x, y, width, height;
width := dim(matrix, 1);
height := dim(matrix, 2);
for y from 0 upto height-1 do
for x from 0 upto width-1 do
write(' ', matrix[x,y]:1)
od;
writeln()
od
corp
 
proc main() void:
[9,9] byte m_odd;
[10,10] byte m_even;
setDiagonals(m_odd);
printMatrix(m_odd);
writeln();
setDiagonals(m_even);
printMatrix(m_even)
corp</lang>
{{out}}
<pre> 1 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
0 0 1 0 0 0 1 0 0
0 1 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 1
 
1 0 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 1 0 0
0 0 0 1 0 0 1 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 1 0 0 1 0 0 0
0 0 1 0 0 0 0 1 0 0
0 1 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 0 1</pre>
 
=={{header|Excel}}==
2,093

edits