Created
November 20, 2021 14:35
-
-
Save zgunz42/4d24bc15d681329aa5d3284944a3115b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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