Sum digits of an integer: Difference between revisions
Content deleted Content added
Updated D entry |
Added Forth version |
||
Line 360:
show [1; 10; 1234; 10; 0xFE; 16; 0xF0E; 16] // -> 1 10 29 29
0</lang>
=={{header|Forth}}==
This is an easy task for Forth, that has built in support for radices up to 36. You set the radix by storing the value in variable BASE.
<lang forth>: sum_int 0 begin over while swap base @ /mod swap rot + repeat nip ;
2 base ! 11110 sum_int decimal . cr
10 base ! 12345 sum_int decimal . cr
16 base ! f0e sum_int decimal . cr</lang>
=={{header|Go}}==
|