Here is another program, advanced version of the previous program, to check if the entered string is a palindrome. Palindrome is a string segment, which reads same from both the directions. The same method is implemented here in the program also.
Logic : The given string is referred by two names, where one is traced by the SOL (Start Of Line) and the other is traced from EOL (End Of Line). In every iteration, the condition is checked, if both the characters are the same. If so, sets a flag, “pal” as true (i.e. 1), and hence prints out the result.
The problem can also solved in another method, where we check by reversing the string and then comparing.
int stpal(char str);
printf(“\n\n\t ENTER A STRING…: “);
pal = stpal(str);
printf(“\n\t THE ENTERED STRING IS A PALINDROME”);
printf(“\n\t THE ENTERED STRING IS NOT A PALINDROME”);
int stpal(char str)
int i = 0, len = 0, pal = 1;
for(i=0; i<len/2; i++)
if(str[i] == str[len-i])
pal = 1;
pal = 0;
Download exe and source code here.