Qn-4.c (774B)
1 /* Write a program to check a string is palindrome or not using 2 user-defined function. */ 3 4 #include <stdio.h> 5 #include <string.h> 6 #include <stdbool.h> 7 #include <ctype.h> 8 9 bool isPalindrome(char str[]); 10 11 int main() { 12 char str[100]; 13 14 printf("Enter a string: "); 15 fgets(str, sizeof(str), stdin); 16 str[strcspn(str, "\n")] = '\0'; 17 if (isPalindrome(str)) { 18 printf("\"%s\" is a palindrome.\n", str); 19 } else { 20 printf("\"%s\" is not a palindrome.\n", str); 21 } 22 return 0; 23 } 24 25 bool isPalindrome(char str[]) { 26 int left = 0; 27 int right = strlen(str) - 1; 28 29 while (right > left) { 30 if (tolower(str[left]) != tolower(str[right])) { 31 return false; 32 } 33 left++; 34 right--; 35 } 36 return true; 37 }