Developing Algorithms Using Strings

AP Computer Science A· difficulty 4/5

Compute digit sum of int n with:

<code>int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } </code></pre> For n = 234, sum is

  • A

    9

    check_circle
  • B

    12

  • C

    15

  • D

    6

Explanation

2 + 3 + 4 = 9.

Want 10 more like this — adaptive to your weak spots?

Related questions