MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / IsArmstrong

Function IsArmstrong

math/armstrong/isarmstrong.go:16–34  ·  view source on GitHub ↗
(number int)

Source from the content-addressed store, hash-verified

14)
15
16func IsArmstrong(number int) bool {
17 var rightMost int
18 var sum int = 0
19 var tempNum int = number
20
21 // to get the number of digits in the number
22 length := float64(len(strconv.Itoa(number)))
23
24 // get the right most digit and break the loop once all digits are iterated
25 for tempNum > 0 {
26 rightMost = tempNum % 10
27 sum += int(math.Pow(float64(rightMost), length))
28
29 // update the input digit minus the processed rightMost
30 tempNum /= 10
31 }
32
33 return number == sum
34}

Callers 1

TestIsArmstrongFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsArmstrongFunction · 0.68