StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Program #30 (U3): Palindrome String Check (case-insensitive)
Download
  1. C Programming
  2. C Programming Practice
Program #29 (U3): Count Words in a Sentence : Program #31 (U3): Call by Value vs Reference (swap)
C Programming Practice

Task: Read a string, ignore case and spaces, compare from both ends and print whether it is a palindrome.

 
#include <stdio.h>

#include <ctype.h>

 
int main(void) {

    char s[512], t[512];

    int c, i=0, j=0;

 
    printf("Enter a string: ");

    while((c=getchar())!='\n' && c!=EOF) { if(i<511) s[i++]=(char)c; }

    s[i]='\0';

 
    for (i=0; s[i]; ++i) {

        if (isalnum((unsigned char)s[i])) t[j++] = tolower((unsigned char)s[i]);

    }

    t[j]='\0';

 
    int l=0, r=j-1, ok=1;

    while(l<r){ if(t[l]!=t[r]){ok=0;break;} ++l; --r; }

 
    printf("%s\n", ok ? "Palindrome" : "Not a palindrome");

    return 0;

}

 

 

Program #29 (U3): Count Words in a Sentence Program #31 (U3): Call by Value vs Reference (swap)
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website