forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharmstrongnumber.go
81 lines (53 loc) · 1.27 KB
/
armstrongnumber.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
This is a simple program in go language to check if a given
number is armstrong number or not. An armstrong number is
a number that is equal to the sum of cubes of its individual digits.
Example : 153 = 1^3+5^3+3^3 = 153!
*/
package main
import (
"fmt"
)
// global variable
var number int
// This fuction checks if the given number is armstrong or not
func check(sum int) {
if(number == sum){
fmt.Print("This is an Armstrong number ")
}else{
fmt.Print("This is not Armstrong number")
}
}
// This function calculates the sum of cubes of digits
func armstrongnumber() {
var sum int
var n int
n = number
sum = 0
var r int
r = 0
for n != 0 {
r = n%10
sum += (r*r*r)
n = n/10
}
// calling the check function
check(sum)
}
// driver function
func main() {
fmt.Print("Enter the number you want to check for :")
// Taking the number as input we need to check
fmt.Scan(&number)
// calling the armstrong number
armstrongnumber()
}
/*
Simple I/O :
a) Is an armstrong number :
Enter the number you want to check for :153
This is an Armstrong number
b) Is not an armstrong number :
Enter the number you want to check for :76
This is not Armstrong number
*/