Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

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) res

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions