How to resolve the algorithm Create a two-dimensional array at runtime step by step in the V (Vlang) programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Create a two-dimensional array at runtime step by step in the V (Vlang) programming language
Table of Contents
Problem Statement
Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then output that element. Finally destroy the array if not done by the language itself.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Create a two-dimensional array at runtime step by step in the V (Vlang) programming language
Source code in the v programming language
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()
}
You may also check:How to resolve the algorithm CUSIP step by step in the Phix programming language
You may also check:How to resolve the algorithm Elementary cellular automaton step by step in the Furor programming language
You may also check:How to resolve the algorithm AKS test for primes step by step in the Pascal programming language
You may also check:How to resolve the algorithm Strip control codes and extended characters from a string step by step in the AWK programming language
You may also check:How to resolve the algorithm String comparison step by step in the Quackery programming language