Write a C++ Program to Reverse a Number using while loop.



Write a C++ Program to Reverse a Number using while loop...

Answer / hr

Solution:
/* 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<<"
Reverse of a Number [ "<<n<<" ] is :: [ "<<rev<<" ]
";
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

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

How to stop class inheritance in C++ with condition that object creation should be allowed

0 Answers  


What Are The Differences Between A C++ Struct And C++ Class?

2 Answers   Wipro,


What is wrong with this statement? std::auto_ptr ptr(new char[10]);

0 Answers   Amazon,


What is bool in C++

0 Answers  


Can we use THIS Pointer in static function – Reason in C++?

0 Answers  


What are the different scope C++ provide ?

0 Answers   Amdocs,


How will you print a list of all unique words from a string which may contain repeated words?

0 Answers   Adobe,


How to reverse a string in C++

0 Answers  


Is there a difference between class and struct?

0 Answers  


Without using third variable write a code to swap two numbers.

0 Answers   Accenture,


What is a COPY CONSTRUCTOR and when is it called?

0 Answers   IBS,


Identify the errors in the following program. #include <iostream> using namespace std; void main() { int i=5; while(i) { switch(i) { default: case 4: case 5: break; case 1: continue; case 2: case 3: break; } i-; } }

1 Answers  


Categories