Tuesday, 2 January 2018

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);
     }

}


No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...