write program for palindrome

Answer Posted / felix

#include<stdio.h>
#include<ctype.h>
#include<string.h>

int isPalindrome( char *s );

int main ( void )
{
int i = 0;
int ch;
char s[100];

while ((ch = getchar()) != '\n') {
if (isalpha(ch)) {
s[i] = ch;
i++;
}
}

if ( isPalindrome(s) == 1) {
printf("Yes, is a palindrome.\n");
} else {
printf("No, not a palindrome.\n");
}

return 0;

}

int isPalindrome( char *s )
{
int i = strlen(s)-1;
int j = 0;

while (j<=i) {
if(s[j] != s[i]) {
return 0;
}
i--;
j++;
}
return 1;
}

Is This Answer Correct ?    114 Yes 85 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does c++ sort work?

579


What are the uses of pointers?

591


Should the member functions which are made public in the base class be hidden?

576


Can non-public members of another instance of the class be retrieved by the method of the same class?

618


When is the destructor called?

617






What are advantages of using friend classes?

654


Name the operators that cannot be overloaded in C++?

592


Can you sort a set c++?

547


What is c++ code?

606


Explain how an exception handler is defined and invoked in a Program.

602


Are strings immutable in c++?

670


What is stl containers in c++?

599


Can a built-in function be recursive?

596


What is a local reference?

685


What are exceptions c++?

609