Q:

C++ Program to Reverse a Number using while loop

belongs to collection: C++ Basic Solved Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Basic Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ Program to Find the Number of Digits in a numb... >>
<< C++ program to Print Multiplication Table of a giv...