Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define false 0
- #define true 1
- int isPalindrome(char str[], int beg, int end);
- int main(void)
- {
- int s = 0;
- char str[] = "abccba";
- s = isPalindrome("abccba", 0, 5);
- printf("%d", s);
- getchar();
- return 0;
- }
- /*
- function gets a string and begining and end points and checks if it is a palindrome or not
- input: the string, beg and end points
- output: if the string is palindrome or not
- */
- int isPalindrome(char str[], int beg, int end)
- {
- int palindrome;
- if (strlen(str) % 2 != 0)
- {
- if (beg <= end)
- {
- if (beg == end)
- {
- return true;
- }
- if (str[beg] == str[end])
- {
- palindrome = isPalindrome(str, beg + 1, end - 1);
- }
- else if (str[beg] != str[end])
- {
- return false;
- }
- }
- }
- else
- {
- if (beg <= end)
- {
- if (beg + 1 == end)
- {
- if (str[beg+1] == str[end])
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- if (str[beg] == str[end])
- {
- palindrome = isPalindrome(str, beg + 1, end - 1);
- }
- else if (str[beg] != str[end])
- {
- return false;
- }
- }
- }
- return palindrome;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement