Skip to content

Commit 83491b1

Browse files
committed
3099. Harshad Number
1 parent f90a3fc commit 83491b1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Harshad Number/kata.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package kata
2+
3+
func sumOfTheDigitsOfHarshadNumber(x int) int {
4+
num := x
5+
var sum int
6+
for num > 0 {
7+
sum += num % 10
8+
num = num / 10
9+
}
10+
11+
if x%sum == 0 {
12+
return sum
13+
}
14+
return -1
15+
}

0 commit comments

Comments
 (0)