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

0394b40665fa78e6264002e59a1b3554?d=identicon&s=25 Luc Lucas (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!
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2017-04-04 07:09
What exactly is your question?
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.