Answer to Question #56990 in C for rajashree g.s

Question #56990
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS