Answers for "go sum of digits in an integer"

Go
0

go sum of digits in an integer

func digitSum(i int) (sum int) {
  for {
    sum += i % 10
    i /= 10
    if i == 0 {
      break
    }
  }
  return
}
Posted by: Guest on April-21-2021

Code answers related to "go sum of digits in an integer"

Browse Popular Code Answers by Language