Skip to content

Commit

Permalink
Practice
Browse files Browse the repository at this point in the history
  • Loading branch information
mskKandula committed Sep 7, 2023
1 parent 098b6ac commit 2d5a31c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Exercises/matrixSum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"fmt"
"math/rand"
"sync"
"time"
)

func main() {
var (
arr [100][100]int
resultarr [100]int
wg sync.WaitGroup
)

for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr); j++ {
arr[i][j] = rand.Intn(10000)
}
}
t1 := time.Now()

for i := 0; i < len(arr); i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
resultarr[i] = rowSum(arr[i])
}(i)
}

fmt.Println(time.Since(t1))
fmt.Println(resultarr)
}

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

0 comments on commit 2d5a31c

Please sign in to comment.