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.
De8fbc9ad96a6e70f8e73457cb0eefd2?d=identicon&s=25 Luc L. (taxman297)
on 2017-03-25 12: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!
3a81ced4012650ca2004c9bff7b18202?d=identicon&s=25 Ronald F. (rovf)
on 2017-04-04 07:09
What exactly is your question?
9d2d160377d47a2144b12d36ab63126f?d=identicon&s=25 Regis d. (raubarede)
on 2017-04-04 12: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.