diff options
| author | Hyder <hyder@hyderhadi.xyz> | 2025-08-16 22:37:45 +0300 |
|---|---|---|
| committer | Hyder <hyder@hyderhadi.xyz> | 2025-08-16 22:37:45 +0300 |
| commit | 890c36fd3d33e310ce9c6821f681a383545e694c (patch) | |
| tree | 81b25fd4aad95efbf16533f86b219c7dd1db9fa7 | |
| parent | ec994a46df4a88f6e7b592827fe89b2f2a7ed221 (diff) | |
Finally i solved this kinda tough exercise i beileve(the palindrome checker), i made it work :D
| -rw-r--r-- | Palindrome/Palindrome.c | 50 | ||||
| -rw-r--r-- | README | 3 |
2 files changed, 52 insertions, 1 deletions
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 <stdio.h> + +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 @@ -10,4 +10,5 @@ CONTENTS - The greatest common divisor exercise solution, in ROOT/GCD/GCD.c - Hexadecimal to integer converter solution, in ROOT/HTOI/HTOI.c - Vowels and consonants counter of a string, in ROOT/VACC/VowelsAndConsonantCounter.c -- Binary(28-bit) to decimal converter, in ROOT/BTD/28bitToDecimal.c
\ No newline at end of file +- Binary(28-bit) to decimal converter, in ROOT/BTD/28bitToDecimal.c +- Palindrome words checker exercise, in ROOT/Palindrome/Palindrome.c
\ No newline at end of file |
