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
How does c++ sort work?
What are the uses of pointers?
Should the member functions which are made public in the base class be hidden?
Can non-public members of another instance of the class be retrieved by the method of the same class?
When is the destructor called?
What are advantages of using friend classes?
Name the operators that cannot be overloaded in C++?
Can you sort a set c++?
What is c++ code?
Explain how an exception handler is defined and invoked in a Program.
Are strings immutable in c++?
What is stl containers in c++?
Can a built-in function be recursive?
What is a local reference?
What are exceptions c++?