ooo TFW 8:06 AM instructure-uploads.s3.amazonaws.com A man, a plan, a For this l
ID: 3702366 • Letter: O
Question
ooo TFW 8:06 AM instructure-uploads.s3.amazonaws.com A man, a plan, a For this lo be a Paladrome, a few assumptions must be = Uppercase and lowercase lettiers are treated as the same characte Non-alphabet characters (space, comma, hyphomexclamaion point) ane ioed In a C++ program named palindrone.epp Create a recursive function nameod isFalindrone) that determines whether a given character aay (string) is a palindrome or not Return type: bool Paramaters: o Pointer to character anay Imeger size of character aay The function considers every character (including non-alphabet charactens) and teats uprcaand lowcrcase versions of the same letler to be difsencnt o Ono is nok considered a palindrome, whercas "otto"is o "my gym" is not considerod palindrome, whorcas "mym"is - In the first call to the isPalindrone function, the first and last character of the charater anay is compared o If they are different, then the character array is not a palindrome o If they are the same, then the character aray may be a palindrome, but the net of the armay must be chocked So, the function is recursively caliled, using the characir aray WTTHOUT e frst and last characters. This process repeats untill there are 0 or 1 charactens) left o The function should print out which nemaining part of the character is being checked Write asain) function that tests the isPalindrome function using ser inut o Prints out the resulting value in a nicely foemated equation, as shows in the samgle esecution A sample run of the peogram is shows below SANFLE RUN Enter a character array to find out if it is a pal indrone : ??0ecar Checking: acecar Checking: aceca Checking: ce Checking: ? racecar is a palindrone! Press any key to conti Eater a charactee azzay to find out st it isa palindone acebas Checking: racebar Checking: aceba Checking: ceb racebar s NO a palindromeExplanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
bool isPalindrome(char* arr , int n)
{
if(n<=0) return true; // handling base case
else
{
printf("Checking: ");
int i=0;
for(i=0;i<n;i++) printf("%c",*(arr+i)); // Printing the current substring
printf(" ");
if((*arr) == *(arr+n-1)) return isPalindrome(arr+1,n-2); // Check first and alst character of current string
// if both are same then check the substring in between else return false
else return false;
}
}
int main()
{
char arr[10000];
scanf("%s",arr);
isPalindrome(arr,strlen(arr)) ? printf("%s is a palindrome! ",arr) : printf("%s is not a palindrome! ",arr) ;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.