pc-ip-05.c (861B)
1 /* 2 * Question 5: 3 * Write a function to check whether a given string is a palindrome. Use this function to determine whether an entered string is Palindrome. 4 */ 5 6 #include <stdio.h> 7 8 int isPalindrome(char[]); 9 10 int main() 11 { 12 char str[51]; 13 printf("Please enter the string (Max: 50 character): "); 14 gets(str); 15 if (isPalindrome(str)) 16 { 17 printf("\nInput string is a palindrome string."); 18 } 19 else 20 { 21 printf("\ninput string is not a palindrome string."); 22 } 23 return 0; 24 } 25 26 int isPalindrome(char str[]) 27 { 28 int low = 0; 29 int high = 0; 30 while (str[high] != '\0') 31 { 32 high++; 33 } 34 high--; 35 if (low == high) 36 { 37 return 1; 38 } 39 while (low < high) 40 { 41 if (str[low] != str[high]) 42 { 43 return 0; 44 } 45 low++; 46 high--; 47 } 48 return 1; 49 }