Given a nonnegative int
variable n
, calculate and print out the sum of the digits of n
. For example, if
n
has the value 1234
, since 1 + 2 + 3 + 4 = 10
, your program should print 10
.
n % 10
to extract the digit in the ones place of n
and use
integer division /
to remove the last digit from a number.
Stuck? You may find these lessons helpful: