Write a C++ Program to Reverse a Number using while loop.
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 |
How to stop class inheritance in C++ with condition that object creation should be allowed
What Are The Differences Between A C++ Struct And C++ Class?
What is wrong with this statement? std::auto_ptr ptr(new char[10]);
What is bool in C++
Can we use THIS Pointer in static function – Reason in C++?
What are the different scope C++ provide ?
How will you print a list of all unique words from a string which may contain repeated words?
How to reverse a string in C++
Is there a difference between class and struct?
Without using third variable write a code to swap two numbers.
What is a COPY CONSTRUCTOR and when is it called?
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-; } }