#include <stdio.h>
#include <string.h>
int main(){
char string[20];
int i, length;
int flag = 0;
printf("Enter a string:");
scanf("%s", string);
length = strlen(string);
for(i=0;i < length ;i++){
if(string[i] != string[length-i-1]){
flag = 1;
break;
}
}
if (flag) {
printf("%s is not a palindrome\n", string);
}
else {
printf("%s is a palindrome\n", string);
}
return 0;
}
<b>Output 1</b>
Enter a string:roor
roor is a palindrome
Press any key to continue . . .
<b>Output 2</b>
Enter a string:rum
rum is not a palindrome
Press any key to continue . . .
To check if a string is a palindrome or not, a string needs to be compared with the reverse of itself.
Consider a palindrome string: radar,
---------------------------
index: 0 1 2 3 4
value: r a d a r
---------------------------

To compare it with the reverse of itself, the following logic is used:
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.