Created
February 6, 2026 03:19
-
-
Save alpheratz0/c18a64133ad4e457c2542b555d193585 to your computer and use it in GitHub Desktop.
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 <limits.h> | |
| #define Start (1) | |
| #define Iterations (sizeof(unsigned long long)*8) | |
| int sum_digits(unsigned long long i) { | |
| if (i<=9) return i; | |
| static char _buf[512] = {0}; | |
| char *p = &_buf[0]; | |
| int sum=0; | |
| snprintf(&_buf[0], sizeof(_buf), "%llu", i); | |
| while (*p) | |
| sum+=(*p++-'0'); | |
| return sum_digits(sum); | |
| } | |
| int main(void) { | |
| for (unsigned long long x = Start, iter = 0; iter < Iterations; ++iter, x*=2) | |
| printf("%d\n", sum_digits(x)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment