Question

(a) Write a Ruby function mean that computes the mean value of an arbitrary number of arguments. Function calls mean (1,2,3,4
0 0
Add a comment Improve this question Transcribed image text
Answer #1

def mean(*value)

sum = 0

count = 0.0

for i in value

    sum = sum + i

    count = count + 1

end

if count==0

    return "no argument"

end

return sum/count

end

mean(1,2,3,4,5)

======================================================
SEE OUTPUT
main.rb E saved - https://Round 1 def mean (value) 2 ruby 2.5.0p sum 0 count 0.0 3.0 4 for l in va lue sum = sum + 1 count co

Add a comment
Know the answer?
Add Answer to:
(a) Write a Ruby function mean that computes the mean value of an arbitrary number of arguments. Function calls mean (1,2,3,4,5) mean 3 ,1 ,and "No arguments". (1) and mean should respect...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT