C (gcc), (削除) 29 (削除ここまで) (削除) 27 (削除ここまで) 25 bytes
f(i){i=i?i%10+f(i/10):0;}
-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;}
-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
badatgolf
- 1.5k
- 6
- 25