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

6 of 6
added 35 characters in body
badatgolf
  • 1.5k
  • 6
  • 25

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

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

Try it online!

-2 bytes thanks to Giuseppe

-2 bytes thanks to c--

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. (削除ここまで) Thanks c-- again.

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 によって変換されたページ (->オリジナル) /