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 a C++ structure differ from a C++ class?

825


Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?

756


How does atoi function work?

844


Is swift better than c++?

714


Can a list of string be stored within a two dimensional array?

745






What is the most powerful coding language?

807


How can you quickly find the number of elements stored in a static array?

824


Who discovered c++?

742


What is an html tag?

811


Name the implicit member functions of a class.

810


What is #include iostream?

962


What is the protected keyword used for?

824


What is the difference between an external iterator and an internal iterator?

824


Difference between inline functions and macros?

746


What is the difference between public and private data members?

849