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


$ include "seed7_05.s7i";
 
const func integer: sumDigits (in var integer: num, in integer: base) is func
  result
     var integer: sum is 0;
  begin
    while num > 0 do
      sum +:= num rem base;
      num := num div base;
    end while;
  end func;
 
const proc: main is func
  begin
    writeln(sumDigits(1,      10));
    writeln(sumDigits(12345,  10));
    writeln(sumDigits(123045, 10));
    writeln(sumDigits(123045, 50));
    writeln(sumDigits(16#fe,  10));
    writeln(sumDigits(16#fe,  16));
    writeln(sumDigits(16#f0e, 16));
  end func;