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 the full name of logo?
How a macro differs from a template?
What do you mean by const correctness?
Explain the difference between struct and class in terms of access modifier.
What is the difference between a template and a macro?
Is it possible to pass an object of the same class in place of object reference to the copy constructor?
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
List different attributes in C++?
What will happen if a pointer is deleted twice?
Differentiate between structure and class in c++.
What is buffer and example?
What is the difference between a reference and a pointer?
What is ifstream c++?
What is operator overloading in c++ example?
How do you print a string on the printer?