- 4

You are making a file downloader. To make the downloads faster, you decide to use concurrency. Each file download will run as a

Can anyone give me some hints on this one pls

25th Jun 2021, 7:17 PM
Kabelo Michael Letlala
Kabelo Michael Letlala - avatar
5 Respostas
+ 9
package main import "fmt" //define the download() function func download(s int, c chan int) { var sum int sum = 0 for i:=0; i<=s; i++ { sum += i } c<-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(<-ch2 + <-ch1 + <-ch3) }
14th Aug 2021, 4:03 PM
Kabelo Michael Letlala
Kabelo Michael Letlala - avatar
+ 1
package main import "fmt" func download(s int, c chan int) { var sum int sum = 0 for i:=0; i<=s; i++ { sum += i } c<-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) fmt.Println(<-ch2 + <-ch1 + <-ch3) }
16th Jul 2022, 4:44 AM
WEKESA M. JOEL
WEKESA M. JOEL - avatar
0
1. create a function with size and channel parameters 2. store sum of size to channel 3. sum all ch with fmt.Println(<-ch1+<-ch2+<-ch3)
16th Jul 2021, 3:26 AM
M Ichsanul
0
answer: package main import "fmt" //define the download() function func download(s int, c chan int) { var sum int sum = 0 for i:=0; i<=s; i++ { sum += i } c<-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(<-ch2 + <-ch1 + <-ch3) }
3rd Jan 2022, 9:21 AM
gulasal ikromova
0
I really need this app but its so slow ?
16th Nov 2023, 4:32 PM
Ayaan Axmed
Ayaan Axmed - avatar