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


Please Help Members By Posting Answers For Below Questions

How do c++ struct differs from the c++ class?

828


What are c++ storage classes?

801


What is a manipulator in c++?

928


Which programming language is best to learn first?

784


What is stream and its types in c++?

765


What do you know about near, far and huge pointer?

792


When not to use object oriented programming?

761


when to use 'mutable' keyword and when to use 'const cast' in c++

1873


What is meant by entry controlled loop? What all C++ loops are exit controlled?

816


What is a storage class used in c++?

811


Differentiate between a constructor and a destructor in c++.

768


How do you invoke a base member function from a derived class in which you have not overridden that function?

836


What is a virtual destructor? Explain the use of it?

740


Write a c++ program to display pass and fail for three student using static member function

3073


String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?

2136