Given an integer, Print the reverse of the number

 Given an integer, write a program to reverse the number.



Method 1:

1. Extract the last digit of the given number by performing mod operation with 10.
    For example: 12 % 10 gives '2' (last digit of 12)
2. Multiply the variable with 10 & Store the remainder to that variable (initially variable is initialized to '0')
3. Divide the number by 10
4. Repeat the process until number is greater than '0'
Implementation:


#include<stdio.h>
int main()
{
     int N,rem,res;
     scanf("%d",&N);
     while(N!=0)
     {
          rem=N%10;
          res=(res*10)+rem;
          N=N/10;
     }
     printf("%d",res);
}


Method 2:

Method 1 does not handle integer of large size greater than "unsigned long long int", so an alternate method is required to reverse any large sized integer. Method 2 handles large values, to reverse it.
The idea is to get the input number as string and reversing the string. As the gcc compilers would not accept the "strrev" function, you can manually write the string reverse function like in the implementation below.

Implementation:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX 10000
int main() 
{
      char str[MAX];
      int i=0,j;
      scanf("%s",str);
      while(str[i])
      {
           i++;
      }
      for(j=i-1;j>=0;j--)
      {
           printf("%c",str[j]);
      }
      return 0;
}


Input

N, The number to be reversed

Output


Reversed Number
Sample Input
 

12345

Sample Output

54321