Write a program to find whether the given number is a palindrome or not using functions.

Source Code

#include<stdio.h>
#include<conio.h>
int palindrome(int num)
{
       int c=0,i,f=0;
       int ar[100];
       for(i=0;i<100;i++)
       {
    ar[i]=0;
       }
       while(num>0)
       {
      ar[c]=num%10;
      c++;
      num/=10;
       }
       for(i=0;i<((c-1)/2);i++)
       {
    if(ar[i]!=ar[c-i-1])
    {
      f=1;
      break;
    }
       }
       return f;
}
int main (int argc, char *argv[])
{
  clrscr();
  int n,p;
  printf("\n Enter the number: ");
  scanf("%d",&n);
  p=palindrome(n);
  printf("\n The number %d is",n);
  if(p==1)
      printf(" not a palindrome");
  else
      printf(" a palindrome");
  getch();
}

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code