Write a program that prints the numbers from n to 1 in reverse order (step of -1). For example, if n = 100, the result will be: 100, 99, 98, …, 3, 2, 1.
Watch this video lesson to learn how to print the numbers from N down to 1 (in reverse order) using a for loop: https://youtu.be/LGPZ-ug3qh0.
We can solve the problem in the following way:
- We read the number
nfrom the console input.
- We create a
forloop by assigning
int i = n.
- We reverse the condition of the loop:
i >= 1.
- We define the size of the step: -1.
- In the body of the loop, we print the value of the current step.
Test your solution here: https://judge.softuni.org/Contests/Practice/Index/514#1.