diff options
| author | Hyder Hadi <hyder@hyderhadi.xyz> | 2026-03-31 13:37:32 +0300 |
|---|---|---|
| committer | Hyder Hadi <hyder@hyderhadi.xyz> | 2026-03-31 13:37:32 +0300 |
| commit | 6b4e1641366f51e27eae78a2506b4b66d3e9cd4c (patch) | |
| tree | b0030b9b9eb4584f3b81a8344f4faa8a759989cd /simple-C-programs/NewPalindrome.c | |
| parent | 30a472f58f204dfbf325b8b389c9f3008aa4c40b (diff) | |
Simple C exercises that i solved :D
Diffstat (limited to 'simple-C-programs/NewPalindrome.c')
| -rw-r--r-- | simple-C-programs/NewPalindrome.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/simple-C-programs/NewPalindrome.c b/simple-C-programs/NewPalindrome.c new file mode 100644 index 0000000..e2402da --- /dev/null +++ b/simple-C-programs/NewPalindrome.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <string.h> + + + +void reverse(char *destination, char *source) { + int length = strlen(source); + int i; + for(i = 0;source[i] != '\0';i++) { + destination[i] = source[length - 1]; + length--; + } + destination[i] = '\0'; +} + +void palindrom(char *input) { + + char tmp_dest[100]; + + reverse(tmp_dest , input); + + for(int i = 0;input[i] != '\0';i++) { + if(input[i] != tmp_dest[i]) { + printf("Not a palindrome\n"); + return; + } + } + printf("the word is a palindrome\n"); + +} + +int main() { + + char source[100]; + char destination[100]; + + fgets(source, sizeof(source), stdin); + + // to lowerCase the input letters + for(int i = 0;source[i] != '\0';i++) { + if(source[i] >= 'A' && source[i] <= 'Z') { + source[i] += 32; + } + } + + source[strcspn(source, "\n")] = '\0'; + palindrom(source); + return 0; +}
\ No newline at end of file |
