C++ Program to Reverse a Number using while loop

By | 25.12.2016

Reverse a Number using while loop


Write a C++ Program to Reverse a Number using while loop. Here’s simple Program to Reverse a Number using while loop in C++ Programming Language.


Reverse of number means reverse the position of all digits of any number. For example reverse of 251 is 152

Here is source code of the C++ Program to Reverse a Number using while loop. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : :


/*  C++ Program to Reverse a Number using while loop  */

#include<iostream>
using namespace std;

int main()
{
    int no,rev=0,r,n;

    cout<<"Enter any positive number :: ";
    cin>>n;

    no=n;

    while(no>0)
    {
         r=no%10;
         rev=rev*10+r;
         no=no/10;
    }
    cout<<"\nReverse of a Number [ "<<n<<" ] is :: [ "<<rev<<" ] \n";

    return 0;
}

Output : :


/*  C++ Program to Reverse a Number using while loop  */

Enter any positive number :: 123456

Reverse of a Number [ 123456 ] is :: [ 654321 ]

Process returned 0

Above is the source code for C++ Program to Reverse Number using while loop which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

4.5 8 votes
Article Rating
Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Sajid

Awesome program

Achini

how to reverse a number with zeroes as the last digits???