Write a program that reads a message and checks whether it is a palindrome or not. Use array name as a pointer to keep track of positions in the array (Ignore special characters).
Sample Run:
Enter a message: Madam, I am Adam.
The message entered is not a palindrome.
how to solve this
is TURBO-C is enough to compile this program
Thanks
1
Expert's answer
2015-06-01T01:42:44-0400
Answer: #include <stdio.h> #include <string.h> using namespace std; int main(){ char x; char*str=new char[100]; int k=0,i; printf("Enter a message: "); while(x!='\n') { scanf("%c",&x); if(((x>='a')&&(x<='z'))|| ((x>='A')&&(x<='Z'))) { str[k]=x; if(((x>='A')&&(x<='Z'))) str[k]-='A'-'a'; k++; } } str[k]='\0'; int good=1; for(i=0;i<strlen(str)/2;i++) if(str[i]!=str[strlen(str)-i-1]) { good=0; break; } if(good) printf("The entered message is a palindrome."); else printf("The entered message is not a palindrome."); return 0; }
Comments
Leave a comment