C program to check a number is palindrome or not using Recursion


#include<stdio.h>
int pal(int n, int cal, int k);
int main( )
{
   int n, k, cal=0, p;
   printf("Enter the number: ");
   scanf("%d",&n);
   k=n;
   p=pal(n,cal,k);
   if(p==1)
       printf("\n%d is palindrome\n",k);
   else
       printf("\n%d is not palindrome\n",k);
   return 0;
}
int pal(int n, int cal, int k)
{
    int i, t=0;
    if(k==cal)
    {
        t=1;
        return t;
    }
    if(n>0)
    {
        i=n%10;
        n=n/10;
        cal=cal*10+i;
        pal(n,cal,k);
     }

}


Post a Comment

1 Comments