The Program in C++ to Display the number in reverse order is given below:
#include <iostream>
using namespace std;
int main() {
int num;
cout <<"Hello Codeauri Family, enter a number here: \n";
cin >>num;
cout << "Well, the number in reverse order is: ";
while (num != 0) {
int digit = num % 10;
cout << digit;
num /= 10;
}
cout << endl;
return 0;
}
Output:
Hello Codeauri Family, enter a number here:
26
Well, the number in reverse order is: 62
Pro-Tips💡
This program prompts the user to enter an integer,
and then uses a while loop to iterate through the digits of the number by using the modulo operator (%
) to get the last digit and then dividing the number by 10 to remove the last digit.
The digits are then printed out in reverse order.
It uses standard input/output library <iostream>
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.