Wednesday, July 20, 2011

Program to check palindrome using recursive function

/*Serial No.96     [swami71.cpp]*/ 

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void reverse(char num[],int a,int b)
    {
    if(a<b)
       {
       if(num[a++]==num[b--])
       reverse(num,a,b);
       else
         {
         printf("not a palindrome.\n");
         getch();
         exit;
         }
       }
    else
      {
      printf("palindrome");
      getch();
      exit(0);
      }
      }
void main()
{
int len;
char num[6];
printf("\n enter the no.");
scanf("%s",num);
len=strlen(num);
len--;
reverse(num,0,len);
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...