Forum: Ruby How extract count of even number and display them

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Luc L. (Guest)
on 2017-03-25 13:55
Hello,
I'm totally new to Ruby and I am trying to code the following:
Print and count even numbers existing before value "N".
Ex: If number 9 is entered, code will print : 0,2,4,6,8 and total count:
5
Any help would be appreciated!
Ronald F. (Guest)
on 2017-04-04 09:09
What exactly is your question?
Regis d. (Guest)
on 2017-04-04 14:02
Luc Lucas wrote in post #1185718:
> Hello,
> I'm totally new to Ruby and I am trying to code the following:
> Print and count even numbers existing before value "N".
> Ex: If number 9 is entered, code will print : 0,2,4,6,8 and total count:
> 5
> Any help would be appreciated!

N=11
puts "nb=#{(N+1)/2}"
(0...N).step(2) {|x| p x}


https://github.com/glurp/ruby-mini-book
This topic is locked and can not be replied to.