Tuesday 17 February 2015

How to reverse a number in C++

Structure of the Problem Requirements 

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 it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

1 comments: Post Yours! Read Comment Policy!▼
Important Note:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.