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 |
What is wrong with this statement? std::auto_ptr ptr(new char[10]);
What is meant by exit controlled loop?
Define an Abstract class in C++?
How does free know the size of memory to be deleted
To solve the 8 Queens problem, which algorithm is used?
What is a memory leak in C++?
What are the different scope C++ provide ?
Identify the error in the following program. include<iostream> using namespace std; void main() { int num[]={1,2,3,4,5,6}; num[1]==[1]num ? cout<<"Success" : cout<<"Error"; }
What are issues if we mix new and free in C++?
What Is A Default Constructor in C++ ?
What is placement new?
What is the difference between virtual functions and pure virtual functions?