C++ Program:

- To reverse a number

Example:

User Input: 153

Output:
Your reversed number : 351

#include <iostream>
using namespace std;

int main() {
  int num,reverse=0;
  cout<<"Enter Your number : ";
  cin>>num;
  while(num!=0){
    reverse=reverse*10+num%10;
    num/=10;
  }
  cout<<"Your reversed number :"<<reverse;
  return 0;
}

Output:

  Enter Your number : 1132
  Your reversed number : 2311
Program
number

Main Logic :

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

Example :

Initially, reverse=0
Let num=15,

Now, reverse=0,num=15 [still 'num' not equal to ZERO]
reverse = 0*10+15%10; // = 5
num=15/10;  // =1;

Now, reverse=5,num=1 [still 'num' not equal to ZERO]
reverse=5*10+1%10;   // =51
num=1/10;  // =1

Now num=0
So finally your reverse number which is 51
Concept

Coming Soon !

Quick
Tutorial

Quote

In order to carry a positive action, we must develop here a positive vision.