Matrix with two diagonals: Difference between revisions

Add CLU
(Add BCPL)
(Add CLU)
Line 539:
1 0 0 0 0 0 0 0 1
</pre>
 
=={{header|CLU}}==
<lang clu>matrix = array[array[int]]
 
diagonals = proc (size: int) returns (matrix)
mat: matrix := matrix$new()
for y: int in int$from_to(1, size) do
line: array[int] := array[int]$new()
for x: int in int$from_to(1, size) do
n: int
if x=y cor size-x=y-1
then n := 1
else n := 0
end
array[int]$addh(line, n)
end
matrix$addh(mat, line)
end
return(mat)
end diagonals
 
print_matrix = proc (s: stream, mat: matrix)
for line: array[int] in matrix$elements(mat) do
for elem: int in array[int]$elements(line) do
stream$puts(s, " " || int$unparse(elem))
end
stream$putl(s, "")
end
end print_matrix
 
start_up = proc ()
po: stream := stream$primary_output()
print_matrix(po, diagonals(9))
stream$putl(po, "")
print_matrix(po, diagonals(10))
end start_up</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|Draco}}==
2,093

edits