Let's create a program that outputs the following sequence.
5 8 11 14 17 20 23 26 29 32
You can see that the first number is 5, and it increases by 3. Generally, this is called the arithmetic progression with the first term 5 and the tolerance 3.
Let's create a program that outputs such a sequence. Since the first term m is given and the tolerance n is given, create a program that outputs up to the 10th number separated by spaces.
The input is given in the following format with the first term m and tolerance n separated by half-width spaces.
One line break is inserted at the end of the last line of the input value.
m n
Output the arithmetic progression with the first term m and the tolerance n separated by spaces from the 1st to the 10th.
3 3
3 6 9 12 15 18 21 24 27 30
5 10
5 15 25 35 45 55 65 75 85 95
1 3
1 4 7 10 13 16 19 22 25 28
python
num = gets.chomp.split(" ").map(&:to_i)
x = num[0]
i = 1
array = []
while i <= 10
array << x
x = x + num[1]
i += 1
end
print array.join(" ")
Recommended Posts