Create a two-dimensional array at runtime: Difference between revisions
Create a two-dimensional array at runtime (view source)
Revision as of 01:46, 6 September 2022
, 1 year agono edit summary
(Adds slope example) |
No edit summary |
||
Line 3,099:
echo array[rows - 1][cols - 1]
unlet array</syntaxhighlight>
=={{header|Vlang}}==
<syntaxhighlight lang="vlang">import os
fn main() {
// input
mut row := os.input("enter rows: ").str()
for elem in row {if elem.is_digit() == false {println('Input Error!') exit(1)}}
mut col := os.input("enter cols: ").str()
for elem in col {if elem.is_digit() == false {println('Input Error!') exit(1)}}
// create 2d array of specified size
mut arr2d := [][]int{len: row.int(), init: []int{len: col.int()}}
// assign values
arr2d[0][0] = 7
// view
println(arr2d)
// clear
arr2d.clear()
}
</syntaxhighlight>
{{out}}
<pre>
enter rows: 3
enter cols: 3
[[7, 0, 0], [0, 0, 0], [0, 0, 0]]
</pre>
=={{header|Wren}}==
|