Qn-4.c (965B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 06 Mar 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a program to check a string is palindrome or not using 9 user-defined function. */ 10 11 #include <stdio.h> 12 #include <string.h> 13 #include <stdbool.h> 14 #include <ctype.h> 15 16 bool isPalindrome(char str[]); 17 18 int main() { 19 char str[100]; 20 21 printf("Enter a string: "); 22 fgets(str, sizeof(str), stdin); 23 str[strcspn(str, "\n")] = '\0'; 24 if (isPalindrome(str)) { 25 printf("\"%s\" is a palindrome.\n", str); 26 } else { 27 printf("\"%s\" is not a palindrome.\n", str); 28 } 29 return 0; 30 } 31 32 bool isPalindrome(char str[]) { 33 int left = 0; 34 int right = strlen(str) - 1; 35 36 while (right > left) { 37 if (tolower(str[left]) != tolower(str[right])) { 38 return false; 39 } 40 left++; 41 right--; 42 } 43 return true; 44 }