bsc

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

root / semester_1 / practice-c / pc-ip-05.c

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 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror