Write a Ruby program to check whether the sum of all the 3's of a given array of integers is exactly 9
- برمجة
- برمجة روبي
- 2021-08-31
- mhanasmh00489829403
الأجوبة
def check_array(nums)
sum = 0
i = 0
while i < nums.length
if(nums[i] == 3)
sum += 3
end
i += 1
end
return (sum == 9);
end
print check_array([3, 5, 3, 3]),"\n"
print check_array([3, 3, 2, 1]),"\n"
print check_array([3, 3, 3, 3]),"\n"
Output:
true false false
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
