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

Palindrome number:

palindrome number can also be definded as a number which is equal to number after reversing its digits.
Example: for e.g. input is 12121, and after reversal of its digits, input number will be 12121.

Logic:

1.Input a number
2.Reverse its digits
3.match reversed number against input number

#include<stdio.h>
#include<conio.h>
int ispalindrome(int num);
int reverse(int n);
int rev=0,rem=0; 
void main()
{
  int num;
  printf("n Enter a number: ");
  scanf("%d",&num);
  if(ispalindrome(num))
  {
    printf("n %d is palindrome number",num); 
  }
  else
  {
    printf("n %d is not palindrome number,"num); 
  } 
 getch();
}

int ispalindrome(int num)
{
  if(num==reverse(num))
  {
     return 1;
  }
  else
  {
    return 0; 
  }
}

int reverse(int n)
{
  if(n)
  {
    rem=n%10;
    rev=rev*10+rem;
    reverse(n/10);
  } 
  return rev;
}

Ouput:

Enter a number: 10201
10201 is palindrome number

Leave a Reply

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