Skip to main content

Practice ยท 4 of 4

Digit sum loop

CHALLENGE
Difficulty: beginner+25 XP

Implement static int DigitSum(int n) โ€” sum of the decimal digits of n's absolute value. DigitSum(0) is 0; DigitSum(-907) is 16. No string conversion: use % and / in a loop.

Back to lesson: Practice: Flow under pressure