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
What is istream c++?
Explain some examples of operator overloading?
Which one between if-else and switch is more efficient?
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
Am studying basic c++ programming, have been given the following assignment. Design a linear program to calculate the maximum stress a material can withstand given a force and a diameter of a circle. To find the required area pi should be defined. Have most of the program sorted out but am at a loss as to how to show the calculations required. Can anyone help?
what is C++ objects?
What is a sequence in c++?
Do the names of parameters have to agree in the prototype, definition, and call to the function?
What are the rules for naming an identifier?
What is the latest version on c++?
Write a program to show polymorphism in C++?
Explain how we implement exception handling in c++?
What are the various oops concepts in c++?
What language is a dll written in?
Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?