Exercise · Loops · lesson 7 of 8
Exercise: digit sum
Write a function func digitSum(n int) int that returns the sum of the decimal digits of n.
digitSum(123)→6digitSum(9045)→18digitSum(0)→0
Constraints: n is from 0 to 1000000000; the number 0 has one digit, and its digit sum is 0.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.