Main page Tasks Volumes Ranking Help

Back to task list

Sum of digits

As any number greater than 9 is represented by several digits, we can calculate the sum of these digits. For example, for numbers 1492 and 1776 we get:

1 + 4 + 9 + 2 = 16
1 + 7 + 7 + 6 = 21

In this task you will be given several numbers and asked to calculate their sums of digits.

Important: while many programming languages have built-in functions to convert numbers to strings (from which digits could be extracted), you should not use this (since your goal is to learn some programming tricks).

Instead you need to implement algorithm with repetitive division by 10 (base of numeral system) and summing up the remainders. Read the Number to digits article for details on the algorithm.

Input data below are in the following format:

Each value is described by 3 numbers. You should multiply the first by the second and add the third.
I.e. if line contains numbers A B C, the value which should be processed is A * B + C.

For answer you should output the same number of results, also separated by space. For example:

input data:
3
11 9 1
14 90 2
111 15 111

answer:
16 21 1
You need to login to get test data and submit solution.