Last active
December 18, 2025 18:23
-
-
Save neps-in/060fb8054a43cd6005c4bdf62a497ab5 to your computer and use it in GitHub Desktop.
Generate all palindrome numbers less than a given number - Improved Version (Clean & Idiomatic C)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdbool.h> | |
| bool isPalindrome(int n) | |
| { | |
| if (n < 0) { | |
| return false; | |
| } | |
| int original = n; | |
| int reversed = 0; | |
| while (n > 0) { | |
| reversed = reversed * 10 + (n % 10); | |
| n /= 10; | |
| } | |
| return original == reversed; | |
| } | |
| int main(void) | |
| { | |
| int limit = 100000; | |
| for (int i = 0; i < limit; i++) { | |
| if (isPalindrome(i)) { | |
| printf("%d\n", i); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment