From 0510d92ae4bc267039a81d7170ec2d9cea7eacfe Mon Sep 17 00:00:00 2001 From: Ravindu007 Date: Mon, 23 Oct 2023 15:23:14 +0530 Subject: [PATCH] palindrome_C --- Coding/C/palindrome.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Coding/C/palindrome.c diff --git a/Coding/C/palindrome.c b/Coding/C/palindrome.c new file mode 100644 index 00000000..eba2196e --- /dev/null +++ b/Coding/C/palindrome.c @@ -0,0 +1,32 @@ +#include +#include + +int isPalindrome(char str[]) { + int left = 0; + int right = strlen(str) - 1; + + while (left < right) { + if (str[left] != str[right]) { + return 0; // Not a palindrome + } + left++; + right--; + } + + return 1; // It's a palindrome +} + +int main() { + char str[100]; + + printf("Enter a string: "); + scanf("%s", str); + + if (isPalindrome(str)) { + printf("'%s' is a palindrome.\n", str); + } else { + printf("'%s' is not a palindrome.\n", str); + } + + return 0; +}