external_5.c (726B)
1 // 5. Write a function that checks whether a given string is a Palindrome or not. 2 3 #include<stdio.h> 4 #include<string.h> 5 #include<ctype.h> 6 7 int isPalindrome(char []); 8 9 int main() { 10 char str[50]; 11 printf("Enter the string (upto 50 char): "); 12 fgets(str, sizeof(str), stdin); 13 if(str[strlen(str) - 1] == '\n') str[strlen(str) - 1] = '\0'; 14 if(isPalindrome(str)) printf("\n\"%s\" is palindrome.", str); 15 else printf("\n\"%s\" is not palindrome.", str); 16 return 0; 17 } 18 19 int isPalindrome(char str[]) { 20 int len = strlen(str); 21 int start = 0, end = len - 1; 22 while(start < end) { 23 if(tolower(*(str + start)) != tolower(*(str + end))) return 0; 24 start++; 25 end--; 26 } 27 return 1; 28 }