C Programming Code Examples C > Strings Code Examples C Program to Check if a given String is Palindrome C Program to Check if a given String is Palindrome This program accepts a string and checks whether a given string is palindrome. - Take a string as input and store it in the array string[]. - Store the same string into the another array reverse_string[] in the reverse fashion. - Using for loop compare the elements of both the arrays. - If all the elements of the array are same, then it is a palindrome. Otherwise it is not a palindrome. #include <stdio.h> #include <string.h> void main() { char string[25], reverse_string[25] = {'\0'}; int j, length = 0, flag = 0; fflush(stdin); printf("Enter a string \n"); gets(string); /* keep going through each character of the string till its end */ for (j = 0; string[j] != '\0'; j++) { length++; } for (j = length - 1; j >= 0; j--) { reverse_string[length - j - 1] = string[j]; } /* * Compare the input string and its reverse. If both are equal * then the input string is palindrome. */ for (j = 0; j < length; j++) { if (reverse_string[j] == string[j]) flag = 1; else flag = 0; } if (flag == 1) printf("%s is a palindrome \n", string); else printf("%s is not a palindrome \n", string); }