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 will you execute a stack using a priority queue? (Push and pop should be in O (1)).

0 Answers   Adobe,


Declare a pointer to a function that takes a char pointer as argument and returns a void pointer.

0 Answers   Alter,


What is the difference between member functions and static member functions?

0 Answers   Alter,


Write a program to read the values a, b and c and display x, where x=a/b–c. Test the program for the following values: (a) a = 250, b = 85, c = 25 (b) a = 300, b = 70, c = 70

1 Answers  


What does it mean to take the address of a reference?

0 Answers   Amazon,






What is conversion constructor in C++

0 Answers   TCS,


What are the major differences between C and C++?

0 Answers   Amazon,


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

0 Answers   Adobe,


What is function overloading and operator overloading in C++?

0 Answers   IBS, TCS,


Write a C++ Program to Find whether given Number is Odd or Even.

1 Answers  


Tell me about virtual function

1 Answers  


What is latest update of C++ ?

0 Answers   Adobe,


Categories