Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The following go program calculates the sum of the square roots of numbers. Each routine runs in its own go routines and sends the message
The following go program calculates the sum of the square roots of numbers. Each routine runs in its own go routines and sends the message on a dedicated channel back to the main program. The program exits too early. Fix the main routine (and only the main routine) to ensure that it finishes with the last received result (not earlier or later). Also make sure that you receive the results in the order they are calculated and not simply sequential in the order the routines are called.
The code language is golang/go
package main import ( "math" "math/rand" time" func numbers (sz int) (res chan float64) res -make (chan float64) go funcO defer close(res) num: 0.0 time.Sleep (time.Duration (rand. Intn (1000)) * time.Microsecond) num math.Sqrt (math.Abs (rand. Float64(O)) num /- float64(sz) resStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started