How to Reverse a Number in C++

This Program will reverse a numbers in C++. For example a user will enter a number 12346 then the program will show the number like 64321.

Source Code

#include<iostream>
using namespace std;
int main() {
int num1 = 0;
int num2 = 0;
cout<<" \t \t \t LEP Tutorials \n \n \n ";
cout<<" Enter Your Number  : ";
 cin>>num1; 

   for( ; num1!= 0 ; )
   {
      num2 = num2 * 10;
      num2 = num2 + num1%10;
      num1 = num1/10;
   }
   cout<<"  Reversed Number    : "<<num2;
   return 0;
}

Output of the Program

 reverse a number in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment