forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
automorphicnumber.go
69 lines (46 loc) · 1.18 KB
/
automorphicnumber.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
/* This is a simple program in go language to find if a give number
is a automorphic number or not. An automorphic number is an
integer whose square ends with the given integer, as (25)2 = 625,
and (76)2 = 5776.
*/
package main
import (
"fmt"
)
// This is a global variable
var n int
// This function tells us if the number is automorphic number or not
func automorphicnumber() {
var number int
var b int
b = n
number = n*n
i := 1
//to construct the last digits
for b != 0 {
i = i*10
b = b/10
}
//checking if the last digits form the orginal number
if((number%i) == n) {
fmt.Print("The given number is Automorphic number!")
}else{
fmt.Print("The given number is not Automorphic number!")
}
}
// driver function
func main() {
fmt.Print("Enter the number you want to check :")
fmt.Scan(&n)
// calling automorphic function
automorphicnumber()
}
/*
Sample I/O :
a) Is Automorphic Number :
Enter the number you want to check :76
The given number is Automorphic number!
b) Is not Automorphic Number :
Enter the number you want to check :7
The given number is not Automorphic number!
*/