Logo

Programming-Idioms

History of Idiom 195 > diff from v15 to v16

Edit summary for version 16 by Pablitoz:
New Go implementation by user [Pablitoz]

Version 15

2022-02-11, 14:12:05

Version 16

2023-02-04, 11:20:46

Idiom #195 Pass a two-dimensional array

Pass an array a of real numbers to the procedure (resp. function) foo. Output the size of the array, and the sum of all its elements when each element is multiplied with the array indices i and j (assuming they start from one).

Idiom #195 Pass a two-dimensional array

Pass an array a of real numbers to the procedure (resp. function) foo. Output the size of the array, and the sum of all its elements when each element is multiplied with the array indices i and j (assuming they start from one).

Variables
a,foo,i,j
Variables
a,foo,i,j
Imports
import "fmt"
Code
func foo(a [][]int) {
	fmt.Println("array is ", len(a)[0], " x ", len(a))
	x := 0
	for _, v1 := range a {
		for _, v2 := range v1 {
			x += v2
		}
	}
	fmt.Println("sum: ", x)
}