RosettaCodeData/Task/Create-a-two-dimensional-array-at-runtime/Nim/create-a-two-dimensional-array-at-runtime.nim
2023-07-01 13:44:08 -04:00

20 lines
371 B
Nim

import strutils, rdstdin
let
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
# Create the rows.
var s = newSeq[seq[int]](h)
# Create the columns.
for i in 0 ..< h:
s[i].newSeq(w)
# Store a value in an element.
s[0][0] = 5
# Retrieve and print it.
echo s[0][0]
# The allocated memory is freed by the garbage collector.