Sum of elements below main diagonal of matrix: Difference between revisions
Sum of elements below main diagonal of matrix (view source)
Revision as of 20:58, 12 February 2024
, 3 months ago→{{header|RPL}}: HP-49/50 version
(Add MATLAB implementation) |
(→{{header|RPL}}: HP-49/50 version) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 633:
Elapsed Time: 0.873 ms.
</pre>
=={{header|EasyLang}}==
<syntaxhighlight>
proc sumbd . m[][] r .
r = 0
for i = 2 to len m[][]
for j = 1 to i - 1
r += m[i][j]
.
.
.
m[][] = [ [ 1 3 7 8 10 ] [ 2 4 16 14 4 ] [ 3 1 9 18 11 ] [ 12 14 17 18 20 ] [ 7 1 3 9 5 ] ]
sumbd m[][] r
print r
</syntaxhighlight>
{{out}}
<pre>
69
</pre>
Line 1,519 ⟶ 1,539:
=={{header|RPL}}==
m r c 2 →LIST GET +
≫ ≫ '<span style="color:blue">∑BELOW</span>' STO▼
'''NEXT NEXT'''
[[1 3 7 8 10]
Line 1,533 ⟶ 1,555:
1: 69
</pre>
{{works with|HP|49/50 }}
« DUP SIZE OBJ→ DROP « > » LCXM
HADAMARD AXL ∑LIST ∑LIST
» '<span style="color:blue">∑BELOW</span>' STO
=={{header|Ruby}}==
Line 1,546 ⟶ 1,572:
{{out}}
<pre>69
</pre>
=={{header|Scala}}==
<syntaxhighlight lang="Scala">
object Main {
def main(args: Array[String]): Unit = {
val matrix = Array(
Array(1, 3, 7, 8, 10),
Array(2, 4, 16, 14, 4),
Array(3, 1, 9, 18, 11),
Array(12, 14, 17, 18, 20),
Array(7, 1, 3, 9, 5)
)
var sum = 0
for (row <- 1 until matrix.length) {
for (col <- 0 until row) {
sum += matrix(row)(col)
}
}
println(sum)
}
}
</syntaxhighlight>
{{out}}
<pre>
69
</pre>
Line 1,576 ⟶ 1,628:
=={{header|Wren}}==
<syntaxhighlight lang="
[ 1, 3, 7, 8, 10],
[ 2, 4, 16, 14, 4],
|