From ea277873aca65aaa0033eec8bc352fcea99c4de0 Mon Sep 17 00:00:00 2001 From: karunvemala7 Date: Thu, 1 Oct 2020 19:49:15 +0530 Subject: [PATCH] Palindrome C Program to Check if a Given String is Palindrome --- palindrome | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 palindrome diff --git a/palindrome b/palindrome new file mode 100644 index 00000000..4330b2b8 --- /dev/null +++ b/palindrome @@ -0,0 +1,30 @@ +#include +#include + +// A function to check if a string str is palindrome +void isPalindrome(char str[]) +{ + // Start from leftmost and rightmost corners of str + int l = 0; + int h = strlen(str) - 1; + + // Keep comparing characters while they are same + while (h > l) + { + if (str[l++] != str[h--]) + { + printf("%s is Not Palindrome", str); + return; + } + } + printf("%s is palindrome", str); +} + +// Driver program to test above function +int main() +{ + isPalindrome("abba"); + isPalindrome("abbccbba"); + isPalindrome("geeks"); + return 0; +}