Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to check whether a string is palindrome or not using recursion in C

2 Answers

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

void check_palindrome_recursion(char s[], int index) {
    int fromend = strlen(s) - (index + 1);
    
    if (s[index] == s[fromend]) {
        if (index + 1 == fromend || index == fromend) {
            printf("Palindrome\n");
            return;
        }
        check_palindrome_recursion(s, index + 1);
    }
    else {
        printf("Not palindrome\n");
    }
}

int main() {
    char s[10] = "abcdcba";

    check_palindrome_recursion(s, 0);
    
    return 0;
}




/*
run:

Palindrome

*/

 



answered Jan 16, 2021 by avibootz
0 votes
#include <stdio.h>
#include <string.h>

int palindrome_recursion(char s[], int index) {
    int fromend = strlen(s) - (index + 1);
    
    if (s[index] == s[fromend]) {
        if (index + 1 == fromend || index == fromend) {
            return 1;
        }
        palindrome_recursion(s, index + 1);
    }
    else {
        return 0;
    }
}

int main() {
    char s[10] = "abcdcba";

    if (palindrome_recursion(s, 0)) {
        printf("Palindrome\n");
    }
    else {
        printf("Not palindrome\n");
    }
    
    
    return 0;
}




/*
run:

Palindrome

*/

 



answered Jan 16, 2021 by avibootz

Related questions

1 answer 176 views
2 answers 165 views
1 answer 127 views
1 answer 144 views
1 answer 164 views
1 answer 181 views
...