Program To Reverse a number

 Program To Reverse  a number

Write a program to generate the reverse of a given number N. Print the corresponding reverse number.

Note : If a number has trailing zeros, then its reverse will not include them. For e.g., reverse of 10400 will be 401 instead of 00401.


Input format :

Integer N

Output format :

Corresponding reverse number

Constraints:

0 <= N < 10^8

Sample Input 1 :

1234

Sample Output 1 :

4321

Sample Input 2 :

1980

Sample Output 2 :

891
C++ Code:
#include<iostream>
using namespace std;

int main() 
{
   int n,rev=0,rem;
   cin>>n;
   while(n>0)
   {
     rem = n%10;
     rev = (rev*10)+rem;
     n = n/10;
   }
   cout<<rev;
	
}




SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment