From 890c36fd3d33e310ce9c6821f681a383545e694c Mon Sep 17 00:00:00 2001 From: Hyder Date: Sat, 16 Aug 2025 22:37:45 +0300 Subject: Finally i solved this kinda tough exercise i beileve(the palindrome checker), i made it work :D --- Palindrome/Palindrome.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Palindrome/Palindrome.c (limited to 'Palindrome/Palindrome.c') diff --git a/Palindrome/Palindrome.c b/Palindrome/Palindrome.c new file mode 100644 index 0000000..5cb3c97 --- /dev/null +++ b/Palindrome/Palindrome.c @@ -0,0 +1,50 @@ +#include + +char *reverse(char *input) { + int len = -1; + for (int i = 0;input[i] != '\0'; i++) { + len += 1; + } + for (int i = 0;i <= len;i++) { + char tmp = input[i]; + input[i] = input[len]; + input[len] = tmp; + len--; + } + return input; +} + +void compareString(char *input1, char *input2) { + int len = -1; + int flags = 0; + for (int i = 0;input1[i] != '\0';i++) { + len += 1; + } + for (int i = 0;i <= len;i++) { + if (input1[i] == input2[len]) { + flags = 1; + len--; + } + else { + flags = 0; + printf("Not a palindrome\n\n"); + break; + } + } + if (!flags == 0) { + printf("This is a palindrome\n\n"); + } +} + + +int main() +{ + + printf("Get me a word to see if it is a palindrome\n\n"); + char inp[1000]; + while (scanf("%s", inp) != EOF) { + char *tmp = reverse(inp); + compareString(inp, tmp); + } + return 0; +} \ No newline at end of file -- cgit v1.2.3