Sunday, March 10, 2024

C Language Recursive Program To Check Palindrome

 #include <stdio.h>
#include <string.h>

int rev(char [], int,int);

int main()
{
   char ch[100];
   printf("Enter a string:");
   scanf("%s",ch);
   printf("\nEntered string is %s",ch);
   int x=rev(ch,0,strlen(ch)-1);
   if(x==1)
   printf("\nPalindrome");
   else
   printf("\nNot Palindrome");
    return 0;
}

int rev(char ch[],int start,int end)
{
   
    if(ch[start]!=ch[end])
    return 0;
    else if(start==end)
    return 1;
    start++;
    end--;
    rev(ch,start,end);
}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner