Using c language write a program to reverse a number and check is it palindrome

C program explains how to reverse a given integer and check whether it is palindrome.

palindrome is a phrase, number, or other sequence of characters which is same as its reverse. means it will read same from front and backwards.

                In this c program we initialize a variable rev to zero, after accepting the number as input from  the user we save that number to a temp variable.

Then use a while loop which mod the number using ten to get digit (remainder) then add that to rev using rev = rev * 10 + digit, finally divide the number by 10 to remove the last digit of the integer.

#include <stdio.h>
#include <conio.h>
void main()
  int   num, temp, digit, rev = 0;
  printf("Enter an integer\n");
  scanf("%d", &num);
  temp = num;        /* original number is stored at temp */
  while(num > 0)
	 digit = num % 10;          /* use mod operator to take the last digit of the number */
	 rev = rev * 10 + digit;    /* add the digit to rev *10 to assign the digit to position */
	 num /= 10;                 /* divide the number by 10 to remove the last digit */
  printf("Given number is = %d\n", temp);
  printf("Its reverse is  = %d\n", rev);
  if(temp == rev )
	  printf("Number is a palindrome\n");    /* check both variables are equal if so it is palindrome else not */   
	  printf("Number is not a palindrome\n");
OUTPUT of C program to reverse a given integer number
Enter an integer
Given number is = 12321
Its reverse is = 12321
Number is a palindrome

Enter an integer
Given number is = 3456
Its reverse is = 6543
Number is not a palindrome