*** paiza How can I achieve Rank C ***? I explained the guideline.
Since the author is mainly learning Ruby, I will explain it in Ruby.
To aim for C rank, you need to master the repetition conditions.
I often use the times method
.
t = gets.to_i
t.times do
puts "hello!"
end
If you execute the above program, hello!
Will be output as many times as you enter.
If you apply it, you can also do the following.
t = gets.to_i
i = 1
t.times do
puts i
i += 1
end
If you execute the above program, integers from 1 to the number will be output in order. Arrays can also be used.
t = gets.to_i
num = []
i = 1
t.times do
num << i
i += 1
end
If you run this program, you will get an array of [1, 2, 3,…, i]
.
In order to aim for paiza rank C, it is first necessary to master this times method.
Recommended Posts