0

C Program to Check if a string is Palindrome or not

Before going in to the program you should know what is a palindrome first.

A palindrome is a word, phrase or a number which reads the same backward as forward. For example,

1. madam
2. civic
3. Madam, I’m Adam
4. A man, a plan, a canal: Panama.
5. No lemon, no melon.

the above phrases can be read same from forward and backward as well.

So basically we have to get the input from the user and reverse it and then compare if both are equal. If it equals then it is a Palindrome.

Let’s write the C program to check if a string is Palindrome or not (Not only strings you can check numbers as well):

Read the comments in the above script to understand each and every line.

You could find lot of examples online for this palindrome program. But here in this code, I am not only reversing the string but also removing special characters, spaces and converting Uppercase to Lowercase. So even if you give the input with spaces and special characters still you can able to check whether the entered string is a Palindrome or not.

Example Output:

Enjoy the day!

agurchand

Technologist, software engineer, blogger with experience in Web development and the Media.

Leave a Reply