c program to check whether a number is palindrome or not using while loop

Palindrome number is:

It is an integer that has same value even after the reversal of its digits.
Example: say the input, Number = 12121, after reversal is done,then Number = 12121. So that 12121 is called palindrome.

#include
#include
int palindrome(int val); 
int rever=0,remain=0; 
void main()
{
  int num;
  printf("\nEnter a number: ");
  scanf("\n%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)
{
  while(val)
  {
    remain=val%10;
    rever=rever*10+remain;
    val=val/10;
  }
  return rever;
}

Ouput:

Enter a number: 12321
12321 is a palindrome no

Leave a Reply

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