RosettaCodeData/Task/Multiplication-tables/Ruby/multiplication-tables.rb

13 lines
259 B
Ruby
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
def multiplication_table(n)
2015-11-18 06:14:39 +00:00
puts " |" + (" %3d" * n) % [*1..n]
puts "----+" + "----" * n
2013-04-10 21:29:02 -07:00
1.upto(n) do |x|
2015-11-18 06:14:39 +00:00
print "%3d |" % x
2013-04-10 21:29:02 -07:00
1.upto(x-1) {|y| print " "}
x.upto(n) {|y| print " %3d" % (x*y)}
2015-11-18 06:14:39 +00:00
puts
2013-04-10 21:29:02 -07:00
end
end
multiplication_table 12