bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

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 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror