Created
April 8, 2014 17:10
-
-
Save radcliff/10157560 to your computer and use it in GitHub Desktop.
Prints a multiplication table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prints a multiplication table | |
puts "Please specify the number of rows and colums:" | |
size = gets.chomp.to_i | |
if size > 0 | |
puts "A multiplication table:" | |
puts | |
size.times do |column_number| | |
print "#{column_number + 1} ".center(5) | |
end | |
puts | |
puts | |
size.times do |row_number| | |
line = "#{row_number + 1}| " | |
size.times do |column_number| | |
line += "#{(column_number + 1) * (row_number + 1)} ".center(5) | |
end | |
puts line | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment