Sample Program
def multiples(n) for i in 1..n product = (n * i).to_s spaces = " " * (4 - product.length) yield spaces + product end " " end
- Print triangular multiplication table
for i in 1..10
puts multiples(i) { |arg| print arg }
end
def multiples(n) for i in 1..n product = (n * i).to_s spaces = " " * (4 - product.length) yield spaces + product end " " end
for i in 1..10
puts multiples(i) { |arg| print arg }
end