Program to Print Triangle of Numbers in Ruby

This example will print the numbers in triangle format with increment numbers

array = (1..10).to_a

order = 1

limit = 4

 

(1..limit).each do |number|

array[order - 1, number].each{|i| print "#{i} " } # will print it in line

order += number

puts # will print a break between your lines

end

 

Output

1 
2 3 
4 5 6 
7 8 9 10 

 


Flutter Questions

Android Questions

Python Questions

Java Questions