Q:

Write a Ruby program to compute the sum of all the elements. The array length must be 3 or more

0

Write a Ruby program to compute the sum of all the elements. The array length must be 3 or more.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def check_array(nums)
   return (nums[0] + nums[1] + nums[2])
end

print check_array([1, 2, 5]),"\n" 
print check_array([1, 2, 3]),"\n" 
print check_array([1, 2, 4]) 

Output:

8
6
7

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now