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


code    ChOut=8, CrLf=9, IntOut=11;
 
func    SumDigits(N, Base);
int     N, Base, Sum;
[Sum:= 0;
repeat  N:= N/Base;
        Sum:= Sum + rem(0);
until   N=0;
return Sum;
];
 
[IntOut(0, SumDigits(1,      10));  ChOut(0, ^ );
 IntOut(0, SumDigits(12345,  10));  ChOut(0, ^ );
 IntOut(0, SumDigits(123045, 10));  ChOut(0, ^ );
 IntOut(0, SumDigits($FE,    10));  ChOut(0, ^ );
 IntOut(0, SumDigits($FE,    16));  ChOut(0, ^ );
 IntOut(0, SumDigits($F0E,   16));  CrLf(0);
]