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; +}