Skip to content

Instantly share code, notes, and snippets.

@radcliff
Created April 8, 2014 17:10
Show Gist options
  • Save radcliff/10157560 to your computer and use it in GitHub Desktop.
Save radcliff/10157560 to your computer and use it in GitHub Desktop.
Prints a multiplication table.
# 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