Write a C program that will determine if an input string is a palindrome - a wor
ID: 3767424 • Letter: W
Question
Write a C program that will determine if an input string is a palindrome - a word, phrase, number, or other sequence of units that may be read the same way in either direction, with general allowances for adjustments to punctuation and word dividers. Your program should ignore spaces, punctuation and case. The user ends the program by entering the word 'quit.' An interactive session with the program might look like this (user input is underlined):
Enter a phrase: Never odd or even.
Never odd or even. is a palindrome.
Enter a phrase: What's up?
What's up? is not a palindrome.
Enter word: Do geese see God?
Do geese see God? is a palindrome.
Enter word: quit
Thank you
Your program must use pointers to access the characters in the string. No array syntax (other than in declarations) can be used.
Hint: Read the message one character at a time (using getchar()) and store the characters in an array. Stop reading when the array is full or the character read is ' '. Do not store non-alpha characters in the new array.
Explanation / Answer
#include <stdio.h>
#include <conio.h>
void main() {
char *a;
int i,len,flag=0;
clrscr();
printf(" ENTER A STRING: ");
gets(a);
len=strlen(a);
for (i=0;i<len;i++) {
if(a[i]==a[len-i-1])
flag=flag+1;
}
if(flag==len)
printf(" THE STRING IS PALINDROM"); else
printf(" THE STRING IS NOT PALINDROM");
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.