In C, write a recursive function int Palindrome(char mystr[], int len) that checks whether the string char mystr[]="....." is a palindrome or not. If it is then print "Palindrome" and if not print "Not palindrome" to the console. A string being a palindrome has 2 cases:(i)if the string has an even length, then the first half is a mirroring of the second half; e.g., abccba is a palindrome, whereas abccab is not. (ii) if the string has an odd length, then disregard of the letter in the middle, the first half is a mirroring of the second half; e.g., abcvcba is a palindrome, whereas abccvba is not.

Respuesta :

#include <stdio.h>

#include <string.h>

int Palindrome(char mystr[], int len)

{

   // base case: if the length of the string is 0 or 1, it is a palindrome

   if (len <= 1)

       return 1;

   // check if the first and last characters are the same

   if (mystr[0] != mystr[len - 1])

       return 0;

   // if the first and last characters are the same, check the substring that

   // lies between them (excluding the first and last characters)

   return Palindrome(mystr + 1, len - 2);

}

int main()

{

   char mystr[] = "abcba";

   int len = strlen(mystr);

   if (Palindrome(mystr, len))

       printf("Palindrome\n");

   else

       printf("Not palindrome\n");

   return 0;

}

This function works by checking the first and last characters of the string. If they match, it calls itself with a substring that excludes the first and last characters. This process continues until the length of the string is 0 or 1, at which point it returns 1 (indicating that the string is a palindrome). If any of the characters do not match, the function returns 0 immediately.

read more about this at https://brainly.com/question/12567947

#SPJ4

ACCESS MORE