C program to check whether given number is palindrome or not using recursive function or recursion

Define palindrome number:

When we reverse digits of number from right to left, then number can be seen as similar number it was previously then it is called palindrome number.
Example: suppose number considered is 121 and after we do reversal then digits of this number still stay same, so that 121 is palindrome number

#include
#include
int palindrome(int val);
int rever=0,remain=0;
void main()
{
  int val;
  printf("n Enter a number: ");
  scanf("%d",&val);
  if(val==palindrome(val))
  {
    printf("\n %d is a palindrome no",val); 
  }
  else
  {
    printf("\n %d is not a palindrome no",val); 
  }
  getch();
} 

int palindrome(int val)
{
  if(val)
  {
    remain=val%10;
    rever=rever*10+remain;
    palindrome(val/10); 
  } 
  return rever;
}

Ouput:

Enter a number: 16461
16461 is a palindrome no

Leave a Reply

error: Content is protected !!
%d bloggers like this: