Skip to content

Instantly share code, notes, and snippets.

@neps-in
Last active December 18, 2025 18:23
Show Gist options
  • Select an option

  • Save neps-in/060fb8054a43cd6005c4bdf62a497ab5 to your computer and use it in GitHub Desktop.

Select an option

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)
#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