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

Explain what happens when an exception is thrown in C++.

0 Answers   Amazon,


Write a C++ Program to Display Number (Entered by the User).

1 Answers  


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  


Implement a 2D bit-matrix representing monochrome pixels which will have only OFF/ON values and will take on an average only one bit of memory for each stored bit. How to perform various operations on it?

0 Answers   Adobe,


Question on Copy constructor.

0 Answers   Alter,






How do you write a function that can reverse a linked-list in C++?

0 Answers   IBS,


Mention the default functions in C++, how would you detect that error has occurred inside the constructor and destructor.

0 Answers   Adobe,


How to convert integer to string in C++

0 Answers  


What are Agilent PRECOMPILERS?

0 Answers   Agilent,


What is data abstraction? How is it implemented in C++?

0 Answers   Amdocs,


Explain the operator overloading feature in C++ ?

0 Answers  


What are pass by value and pass by reference?what is the disadvantage of pass by value?

0 Answers   Alter,


Categories