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

Palindrome number:

It is an integer number that stays same after reversal of its digits.
Example: say value of integer is, N = 121, then output will be 121. So that value 121 is called palindrome.

#include
#include
int palindrome(int val); 
int rever=0,remain=0; 
void main()
{
  int num;
  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)
{
  do
  {
    remain=val%10;
    rever=rever*10+remain;
    val=val/10;
  }while(val>0);
  return rever;
}

Ouput:

Enter a number: 12121
12121 is a palindrome

Leave a Reply

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