C Program to Check a String is Palindrome or not

A palindrome is a string that reads the same forward and backward. Here’s a simple C program that checks whether a given string is a palindrome or not.

Program :

#include <stdio.h>
#include <string.h>
int main() {
char string1[20];
int i, length;
int flag = 0;
printf(“Enter a string: “);
scanf(“%s”, string1);
length = strlen(string1);
for (i = 0; i < length / 2; i++) {
if (string1[i] != string1[length – i – 1]) {
flag = 1;
break;
}
}
if (flag) {
printf(“%s is not a palindrome\n”, string1);
} else {
printf(“%s is a palindrome\n”, string1);
}
return 0;
}

Output :

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights