-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathneonnumber.go
75 lines (48 loc) · 1.14 KB
/
neonnumber.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
/* This is a simple program in go language to check if a given number is neon number
or not. A neon number is a number where the sum of digits of the square of the
number should be equal to the initial number.
*/
package main
import (
"fmt"
)
// variables declared globally
var n int
var r int
var sum int
var square int
// This function calculates the sum of digits of a number
func Sum(square int) {
for square != 0{
r = square%10
sum += r
square = square/10
}
}
// This function checks if a number is a neon number or not
func neon() {
//calling sum function to calculate the sum
Sum(square)
if (sum == n){
fmt.Print("The given number is a neon number !")
}else{
fmt.Print("The given number is not a neon number !")
}
}
//driver function
func main() {
fmt.Print("Enter the number here :")
fmt.Scanln(&n)
square = n*n
//calling the neon function
neon()
}
/*
Sample I/O :
a) Is a neon number :
Enter the number here :9
The given number is a neon number !
b) Is not a neon number :
Enter the number here :12
The given number is not a neon number !
*/