Write a C++ Program to Reverse a Number using while loop.
Answer Posted / 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 View All Answers
What is flush programming?
What's the order in which the local objects are destructed?
What is #include math h in c++?
Which is better turbo c++ or dev c++?
What is the precedence when there is a global variable and a local variable in the program with the same name?
How do I tokenize a string in c++?
What is the best c++ compiler?
Is c++ double?
What do the header files usually contains?
How do you invoke a base member function from a derived class in which you have not overridden that function?
Explain the differences between list x; & list x();.
What is stack unwinding?
Differentiate between structure and class in c++.
Explain explicit container.
Explain the difference between method overriding and method overloading in C++?