66 951
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #52787 in C for raghu

Question #52787
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

Expert's answer
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions