C++ Exercises: Display the number in reverse order
C++ For Loop: Exercise-30 with Solution
Write a program in C++ to display the numbers in reverse order.
Pictorial Presentation:

Sample Solution:-
C++ Code :
#include <iostream>
using namespace std;
int main()
{
int num, r, sum = 0, t;
cout << "\n\n Display the number in reverse order:\n";
cout << "-----------------------------------------\n";
cout << " Input a number: ";
cin >> num;
for (t = num; num != 0; num = num / 10)
{
r = num % 10;
sum = sum * 10 + r;
}
cout << " The number in reverse order is : " << sum << endl;
}
Sample Output:
Display the number in reverse order: ----------------------------------------- Input a number: 12345 The number in reverse order is : 54321
Flowchart:

C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to find LCM of any two numbers using HCF.
Next: Write a program in C++ to find out the sum of an A.P. series.
What is the difficulty level of this exercise?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join