Q:

Write a Ruby program to get the number of even integers in a given array

0

Write a Ruby program to get the number of even integers in a given array.

All Answers

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

def check_array(nums)
  count = 0    
  nums.each do |item|
    if((item % 2) == 0)
	count=count + 1
    end 
  end   
  return count
end
print check_array([3, 4, 5, 6]),"\n"
print check_array([3, 4, 5]),"\n"
print check_array([3, 4]) 

Output:

2
1
1

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