I am a project manager, consultant, and social media manager. My interests range from technology to programming. I am also interested in cycling, music, and fashion.
You can click the button above to hire me.
Palindrome example with C programming
Get link
Facebook
X
Pinterest
Email
Other Apps
-
#include<stdio.h>
char lower(char c){
if('A' <= c && 'Z' >= c)
return (c + 32);
return c;
}
int alpha(char c){
c = lower(c);
return (('a' <= c && 'z' >= c));
}
int palindrome(char *str){
char *head = str, *tail = str;
while(*tail) tail ++;
tail --;
while(head <= tail){
if(!alpha(*head)){
head ++;
continue;
}
if(!alpha(*tail)){
tail --;
continue;
}
if(lower(*head) != lower(*tail))
break;
head ++;
tail --;
}
return (tail < head);
}
void main(){
char sentence[200];
printf("Enter a message: ");
fflush(stdin);
gets(sentence);
if(palindrome(sentence)){
printf("Palindrome\n");
return;
}
printf("Not a palindrome\n");
}
Comments
Post a Comment