C++ Program to reverse an integer number using do while
Program
#include<iostream>
using namespace std;
int reverseInt(int num)
{
int remainder,rev=0;
do
{
remainder=num%10;
rev=rev*10+remainder;
num/=10;
}while(num>0);
return rev;
}
int main()
{
int num;
cout << "Enter an Integer: ";
cin >> num;
cout << "Reversed Number: " << reverseInt(num);
return 0;
}
Output
$ g++ reverse-integer-number-using-do-while.cpp
$ ./a.out
Enter an Integer: 987456321
Reversed Number: 123654789