A program in C++ to reverse a digit.

In the above C++ program to reverse a digit, arithmetic operation is used to get the desired result.

#include <iostream>
using namespace std;

int main() {

  int num, rev_num = 0, remainder;

  cout << "Enter an integer: ";
  cin >> num;

  while(num != 0) {
    remainder = num % 10;
    rev_num = rev_num * 10 + remainder;
    num /= 10;
  }

  cout << "Reversed Number is : " << rev_num;

  return 0;
}
Sample Output:
Enter an integer: 4367
Reversed Number is : 7634