Question

C Program A palindrome consists of a word or deblanked, unpunctuated phrase that is spelled exactly...

C Program

A palindrome consists of a word or deblanked, unpunctuated phrase that is spelled exactly the same when the letters are reversed. Write a recursive function that returns a value of 1 if its string argument is a palindrome. Notice that in palindromes such as level, deed, sees, and Madam I'm Adam (madamimadam), the first letter matches the last, the second matches the next-to-last, and so on.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <string.h>

int is_palindrome(char str[], int start, int end) {
    if(start < end) {
        return str[start] == str[end] && is_palindrome(str, start + 1, end - 1);
    } else {
        return 1;
    }
}

int main() {
    char str[100];
    while(1) {
        printf("Enter a string: ");
        scanf("%s", str);
        if(strcmp(str, "STOP") == 0 || strcmp(str, "stop") == 0 || strcmp(str, "Stop") == 0) {
            break;
        }
        if(is_palindrome(str, 0, strlen(str)-1)) {
            printf("%s is a palindrome\n", str);
        } else {
            printf("%s is not a palindrome\n", str);
        }
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
C Program A palindrome consists of a word or deblanked, unpunctuated phrase that is spelled exactly...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT