Challenge: Countdown
Completed
Read a number n and count down from n to 1, each number on its own line. Then print Go!
Input
One integer n (1 or more).
Output
n lines of numbers, then Go!
Example
Input
3
Output
3 2 1 Go!
Editor
C++
Hints
Start the loop at n and use i-- to go down.
Keep going while i >= 1.
Solution explanation
A for loop that starts at n and steps down by one each round.
Show solution
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = n; i >= 1; i--) {
cout << i << "\n";
}
cout << "Go!\n";
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module