23/02/2023

String Palindrome Program in C With Explanation | Source Code

Source Code to String Palindrome Program in C With Explanation. Write a program to check whether a string is a palindrome or not. First, we have to know what is palindrome String?. Palindrome is a word, phrase, or sequence that reads the same backwards as forwards, e.g. madam civic, radar, level and rotor. So basically in this problem, we have to compare the string's first index to the string's last index and the second index to the second last index one by one and so on.

String Palindrome Program in C

We can do this by putting the condition if string[start++] is equal to string[ends--] then the string is a palindrome or if this condition fails then the string is not a palindrome. One more thing I want to clarify Palindrome may not only word, Palindrome may be a sentence.

String Palindrome Words Examples

  • Madam
  • Civic
  • Radar
  • Level, 
  • Rotor
  • Mom
  • Malayalam

Facts about Malayalam (Southern Indian language) Malayalam is the only language that is Palindrome in both Hindi and English, which means if you write Malayalam in English and Malayalam in Hindi " मलयालम " both are Palindrome.

Palindrome Sentence Example

  • Was it a car or a cat I saw
  • Murder for a jar of red rum
  • King, are you glad you are king
  • Yo, banana boy

String Palindrome Program in C Code


#include <stdio.h>
#include <string.h>

/*Write a program to check whether a string is palindrome or not */

void main()
{
	while (1)
	{
		char string1[20];
		int i, length;
		int flag = 0;

		printf("\n\nEnter a String to Check Palindrome String: ");
		scanf("%s", string1);

		length = strlen(string1);

		for (i = 0; i < length; i++)
		{
			if (string1[i] != string1[length - i - 1])
			{
				flag = 1;
				break;
			}
		}

		if (flag)
		{
			printf("\n\n%s Is Not a Palindrome String\n", string1);
		}
		else
		{
			printf("\n\n%s Is Palindrome String\n", string1);
		}
	}

	return 0;
}

String Palindrome Program in C

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: