C Program to Check if a Given String is Palindrome or Not
Test Case
Test #1
Input String : abcba
abcba is a Palindrome.
Test #2
Input String : abcde
abcba is not a Palindrome.
Source Code
#include <stdio.h> #include <string.h> #include <stdbool.h> //visit us @hobingoding.com int main(){ char string[50]; bool palindrome = true; printf("Input String : "); scanf("%s", &string); for(int i = 0; i < strlen(string); i++){ string[i] = tolower(string[i]); } for(int i = 0; i < strlen(string)/2; i++){ if(string[i] != string[strlen(string)-i-1]){ palindrome = false; break; } } if(palindrome) printf("%s is a Palindrome.", string); else printf("%s is not a Palindrome.", string); return 0; }
Post a Comment for "C Program to Check if a Given String is Palindrome or Not"