Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int test(char* string)
- {
- int len = strlen(string);
- if(len > 1)
- {
- if(*string == *(string + len - 1)) //If first char equals the last.
- {
- *(string + len - 1) = 0;
- string++;
- return test(string);
- }
- else
- return 0;
- }
- else
- return 1; //One letter strings are palindromes anyway
- }
- void main()
- {
- char teststr[] = "ababa"; //Try other cases.
- if(test(teststr) == 1)
- printf("Palindrome success\n");
- else
- printf("Fail\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement