0
How to return the sum of a number in ruby?
sum(num) end sum(4) # => 10 because 1+2+3+4 = 10
2 odpowiedzi
0
For example:
https://code.sololearn.com/ctIjDQU3GLUv/?ref=app
0
def sum(num)
i = 0
sum = 0
while i < num
i += 1
sum += i
end
return sum
end
puts sum(4)
puts sum(3)