# Input
# You are given an integer N depicting the height of the staircase.
# Output
# Print a staircase of height N that consists of # symbols and spaces.
p "Enter the height of staircase :"
n = gets.strip.to_i
# 1st Method :
def staircase(space , hash)
puts " "*space + "#"*hash
end
for i in (1..n)
staircase(n-i , i)
end
#2nd Method :
n.times{|i| puts ("#"*(i+1)).rjust(n)}
# You are given an integer N depicting the height of the staircase.
# Output
# Print a staircase of height N that consists of # symbols and spaces.
p "Enter the height of staircase :"
n = gets.strip.to_i
# 1st Method :
def staircase(space , hash)
puts " "*space + "#"*hash
end
for i in (1..n)
staircase(n-i , i)
end
#2nd Method :
n.times{|i| puts ("#"*(i+1)).rjust(n)}
No comments:
Post a Comment