Recursive function for string palindrome

January 29, 2011 at 01:50:22
Specs: Windows XP
Is it possible to write a recursive function to check palindrome string in C? Pls give some suggestions.

See More: Recursive function for string palindrome

Report •

#1
January 29, 2011 at 03:07:34
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char palindrome(char *,int);
main(){
char x[50],y[50];
int i=0,j=0,r=0;
printf("Type the string\n");
gets(x);
while (x[j]!='\0'){
if (x[j]>='A' && x[j]<='Z') /*turning CAPS into lowercase*/
y[r++]=x[j]+('A'-'a');
else if (x[j]!=' ') /*removing spacesfrom the string*/
y[r++]=x[j];
j++;
}
if (palindrome (y,i)==1)
printf("Palindrome\n");
else printf ("Not a palindrome\n");
getchar();
}
char palindrome(char a[],int i){ /*'k' is set as the length of our string*/
int k;
k=strlen(a);
if (k<2) return 1;
else if (a[i]!=a[k-i]) return 0; /*comparing first and last char*/
else return palindrome(a,i+1); /*increasing 'i' by 1*/
}

Report •

#2
January 29, 2011 at 06:42:03
. . . Really, desertstar? You registered just to do other people's homework for them?

How To Ask Questions The Smart Way


Report •

#3
January 29, 2011 at 09:52:24
had to subscribe some day :/ Dont worry it was 2 steps GOOGLED ctrl c and ctrl v ;)

Report •
Related Solutions


Ask Question