14 July, 2011

String Palindrome - Recursive function

Hi all,

Write a program to find whether the given string is palindrome or not with the help of recursive functions.

NOTE: There are many ppl who are not active in this forum, i request them to wake up and reply to the questions posted or atleast to post some questions. Else those ppl will be removed from this forum.

2 comments:

  1. Check this code... I wrote and tested it... I think it is fine...


    #include
    #include
    #include
    void rec_func(char str[10], int i, int j );
    int check = 0;
    int main(void)
    {
    char str[100];
    printf("Enter the string\n");
    scanf("%[^\n]s",str);
    printf("The string u entered is %s\n",str);
    int str_len = strlen(str);
    int i = 0;
    int j = str_len -1;


    rec_func(str,i , j);
    if(check == 0){
    printf("String is palindrome\n");
    } else {
    printf("String is not palindrome\n");
    }
    return 0;
    }

    void rec_func(char str[10], int i, int j )
    {
    if((i == j)|| (i > j)){
    return;
    } else {
    if(str[i] == str[j]){
    i++;
    j--;
    rec_func(str,i,j);
    }else{
    check = 1;
    return;
    }
    }
    }

    ReplyDelete
  2. I dont know why all the header files got omitted..
    Any way add stdio.h, string.h, and stdlib.h(optional) header files.

    ReplyDelete