Header Ads Widget

Ticker

6/recent/ticker-posts

C++ Program to reverse number by Digitalise Data

C++ Program to reverse number by Digitalise Data

 C++ Program to reverse number

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.h>
  2. #include <conio.h>  
  3. void 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. getch(); 
  16. }  

Output:

Enter a number: 234  
 Reversed Number: 432

Post a Comment

0 Comments