Skip to content

Instantly share code, notes, and snippets.

@zgunz42
Created November 20, 2021 14:35
Show Gist options
  • Save zgunz42/4d24bc15d681329aa5d3284944a3115b to your computer and use it in GitHub Desktop.
Save zgunz42/4d24bc15d681329aa5d3284944a3115b to your computer and use it in GitHub Desktop.
package main
import "fmt"
//define the download() function
func download(value int, ch chan int) {
sum :=0
for i:=0; i <= value; i++ {
sum +=i
}
ch <- sum
}
func main() {
ch1 := make(chan int)
ch2 := make(chan int)
ch3 := make(chan int)
var s1, s2, s3 int
fmt.Scanln(&s1)
fmt.Scanln(&s2)
fmt.Scanln(&s3)
go download(s1, ch1)
go download(s2, ch2)
go download(s3, ch3)
//output the sum of all results
fmt.Println(<-ch1 + <-ch2 + <-ch3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment