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
Expert's answer
#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;
}
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 orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment