Print Numbers from 10 to 1 in Reverse Order in C++

In this exercise, you will write a C++ program that prints numbers from 10 to 1 in reverse order. This will help you practice using loops, particularly with decrementing values. By using a `for` loop or a `while` loop, you can iterate through a sequence in reverse.

The program will start from 10 and decrease the value with each iteration until it reaches 1, printing each number on a new line.

This exercise demonstrates how to control the flow of a program in reverse order using a decrementing loop.

Group

Flow Control in C++

Objective

1. Use a loop to iterate from 10 to 1.
2. In each iteration, print the current number.
3. Test the program to ensure that the numbers are printed in reverse order from 10 down to 1.

Write a program that prints the numbers from 1 to 10 in reverse order.

Example C++ Exercise

 Copy C++ Code
#include <iostream> // Include the iostream library for input and output

using namespace std; // Use the standard namespace

// Main function - the entry point of the program
int main() {
    // Use a for loop to iterate from 10 to 1
    for (int i = 10; i >= 1; --i) {
        cout << i << endl; // Print the current value of i (the number)
    }

    return 0; // Return 0 to indicate that the program executed successfully
}

 Output

10
9
8
7
6
5
4
3
2
1

Share this C++ Exercise


More C++ Programming Exercises of Flow Control in C++

Explore our set of C++ Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C++. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C++.