Search Your Topic

config
Thursday, 22 June 2017 12:50

C++ Program to reverse number

Written by
Rate this item
(0 votes)

We can reverse a number in C++ using loop and arithmetic operators. In this program, we are getting number as input from the user and reversing that number.

Let's see a simple C++ example to reverse a given number.

 
  1. #include <iostream>  
  2. using namespace std;  
  3. int main()  
  4. {  
  5. int n, reverse=0, rem;    
  6. cout<<"Enter a number: ";    
  7. cin>>n;    
  8.   while(n!=0)    
  9.   {    
  10.      rem=n%10;      
  11.      reverse=reverse*10+rem;    
  12.      n/=10;    
  13.   }    
  14.  cout<<"Reversed Number: "<<reverse<<endl;     
  15. return 0;  
  16. }  

Output:

Enter a number: 234  
 Reversed Number: 432
Read 241 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.