C Program to check whether a string is palindrome or not

What is a Palindrome?

A number or a word which remains the same, even after being reversed is called palindrome. For example, mom, radar, or the number 45654, all are palindrome.

The following is a C program to determine whether a string is a palindrome or not.

Expected Output:

1st run:

2nd run:

Related Program: C Program to check whether the number is a Palindrome

How it works

The following table demonstrates what happens at each iteration of the while loop, assuming word =  radar.

Iteration Condition i j
After 1st iteration word[0]!=word[1]=>'r'!='r'=>0 i=1 j=3
After 2nd iteration word[1]!=word[3]=>'a'!='a'=>0 i=2 j=2
After 3rd iteration word[2]!=word[2]=>'d'!='d'=>0 i=3 j=1

Hence, the string radar is palindrome.

Recommended Reading:


Leave a Comment

%d bloggers like this: