golang sum of digits code example
Example: go sum of digits in an integer
func digitSum(i int) (sum int) {
for {
sum += i % 10
i /= 10
if i == 0 {
break
}
}
return
}
func digitSum(i int) (sum int) {
for {
sum += i % 10
i /= 10
if i == 0 {
break
}
}
return
}