Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

5 of 6
added 62 characters in body
badatgolf
  • 1.5k
  • 6
  • 25

C (gcc), (削除) 29 (削除ここまで) 27 bytes

f(i){i=i%10+(i?f(i/10):0);}

Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

The bracket around the ternary is truly awful. Wish I could remove that.

C (gcc), (削除) 38 (削除ここまで) 36 bytes (no recursion).

a;f(i){for(a=0;i;i/=10)a+=i%10;a=a;}

Try it online!

-2 bytes thanks to Giuseppe

Takes input as int.

C's int isn't large enough for the last test case.

C (gcc), 56 bytes (no recursion) (outgolfed by c-- using recursion).

a,n;f(char*s){for(a=0,n=strlen(s);n--;++s)a+=*s-48;a=a;}

Takes input as string

Try it online!

badatgolf
  • 1.5k
  • 6
  • 25

AltStyle によって変換されたページ (->オリジナル) /