Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/farseer-go/utils into main
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Nov 9, 2024
2 parents 83a8d28 + 7337c99 commit eaed62a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions operator/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (

// GetSum 取和数
func GetSum(num int) int {
sum := 0
// 迭代每一位数字
for num != 0 {
digit := num % 10 // 每次取个位数
sum += digit // 将个位数加到总和上
num /= 10 // 去掉个位数
}
return sum
return num/10 + num%10
// sum := 0
// // 迭代每一位数字
// for num != 0 {
// digit := num % 10 // 每次取个位数
// sum += digit // 将个位数加到总和上
// num /= 10 // 去掉个位数
// }
// return sum
}

// GetTail 取数字的个位数
Expand Down

0 comments on commit eaed62a

Please sign in to comment.