w3resource

Ruby Basic Exercises: Print odd numbers from 10 to 1

Ruby Basic: Exercise-28 with Solution

Write a Ruby program to print odd numbers from 10 to 1.

Ruby Basic Exercises: Print odd numbers from 10 to 1

Ruby Code:

puts "Odd numbers between 9 to 1: "
9.step 1, -2 do |x|
      puts "#{x}"
 end

Output:

Odd numbers between 9 to 1: 
9
7
5
3
1

Flowchart:

Flowchart: Print odd numbers from 10 to 1

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to print even numbers from 1 to 10.
Next: Write a Ruby program to print the elements of a given array.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/ruby-exercises/basic/ruby-basic-exercise-28.php