Task

Take a   Natural Number   in a given base and return the sum of its digits:

   110         sums to   1
   123410   sums to   10
   fe16       sums to   29
   f0e16     sums to   29


 
func sum_digits(n : int, base : int) -> int {
    var sum = 0;
 
    do
    {
        sum = sum + n % base;
        n = n / base
    }
    while (n != 0);
 
    sum
}
 
func main() -> int {
    print(sum_digits(1, 10));
    print(sum_digits(12345, 10));
    print(sum_digits(123045, 10));
    print(sum_digits(0xfe, 16));
    print(sum_digits(0Xf0e, 16));
 
    0
}
 