C program to check whether given number is palindrome or not using for loop

Define Palindrome number:

Palindrome number is viewed with same value after we do reversal of its digits.
Example: Say number is, number = 212, then reversal of its digits will make output be like number = 212. so that here 212 is a palindrome.

#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",val);
  }
  else
  {
    printf("\n %d is not a palindrome",val); 
  } 
  getch();
}
int palindrome(int val)
{
  for(;val>0;val=val/10)
  {
    remain=val%10;
    rever=rever*10+remain;
  }
  return rever;
}

Ouput:

Enter a number: 212
212 is a palindrome

Leave a Reply

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