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

What is the full name of logo?

566


How a macro differs from a template?

612


What do you mean by const correctness?

597


Explain the difference between struct and class in terms of access modifier.

658


What is the difference between a template and a macro?

558






Is it possible to pass an object of the same class in place of object reference to the copy constructor?

545


Would you rather wait for quicksort, linear search, or bubble sort on a 200000 element array? (Or go to lunch...) a) Quicksort b) Linear Search c) Bubble Sort

609


List different attributes in C++?

620


What will happen if a pointer is deleted twice?

701


Differentiate between structure and class in c++.

571


What is buffer and example?

504


What is the difference between a reference and a pointer?

572


What is ifstream c++?

533


What is operator overloading in c++ example?

620


How do you print a string on the printer?

553