Skip to content

Commit

Permalink
Matrix Columns Sum
Browse files Browse the repository at this point in the history
  • Loading branch information
mskKandula committed Sep 8, 2023
1 parent e857d29 commit 31fe857
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Exercises/matrixColSum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"fmt"
)

func main() {
var (
arr [5][5]int
resultarr [5]int
)

for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr); j++ {
arr[i][j] = i
}
}

for i := 0; i < len(arr); i++ {
var colArr []int
for j := 0; j < len(arr); j++ {
colArr = append(colArr, arr[j][i])
}
resultarr[i] = colSum(colArr)
}

fmt.Println(resultarr)
}

func colSum(arr []int) int {
var result int
for _, val := range arr {
result += val
}
return result
}

0 comments on commit 31fe857

Please sign in to comment.