write a program to accept a string and find out if it is a palindrome
1
Expert's answer
2016-01-19T08:44:11-0500
#include <stdio.h>
int isPalindrome(char *str);
int main() { char str[100]; printf("Enter your string:"); scanf("%s", str); if(isPalindrome(str) == 1) printf("It is palindrome.\n"); else printf("It is NOT palindrome.\n"); }
int isPalindrome(char *str) { int i, len = 0; while (str[len] != '\0') len++; for(i = 0; i < len/2; i++) { if(str[i] != str[len - 1 - i]) return 0; } return 1; }
Comments
Leave a comment