From 29edbed58b62de76d9ddb3d919c51c9a86ea09d4 Mon Sep 17 00:00:00 2001 From: Ananthakrishnan Nair RS <61831021+akrish4@users.noreply.github.com> Date: Wed, 16 Dec 2020 19:45:49 +0530 Subject: [PATCH] added strings topic --- STRINGS/c or cpp/Palindrome.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 STRINGS/c or cpp/Palindrome.c diff --git a/STRINGS/c or cpp/Palindrome.c b/STRINGS/c or cpp/Palindrome.c new file mode 100644 index 00000000..d6e1c250 --- /dev/null +++ b/STRINGS/c or cpp/Palindrome.c @@ -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"); + return 0; +}