-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathautomorphic_neon_magic_number.c
143 lines (117 loc) · 2.28 KB
/
automorphic_neon_magic_number.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
AUTOMORPHIC NUMBER
GFG LINK:-"https://www.geeksforgeeks.org/automorphic-number/"
SOLUTION TO PROBLEM:-
For Input:
76
your output is:
Automorphic
#include<bits/stdc++.h>
using namespace std;
class Solution
{
public:
string is_AutomorphicNumber(int n)
{
// Code here
string s="NotAutomorphic";
int num=n*n;
while(n>0)
{
if(n%10!=num%10)
return s;
n=n/10;
num=num/10;
}
s="Automorphic";
return s;
}
};
// { Driver Code Starts.
int main(){
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
Solution ob;
string ans = ob.is_AutomorphicNumber(n);
cout << ans <<"\n";
}
return 0;
} // } Driver Code Ends
NEON CODE
refered document link:-"https://www.quora.com/What-are-10-neon-numbers"
#include <iostream>
using namespace std;
#include <math.h>
int checkNeon(int x)
{
// storing the square of x
int sq = x * x;
// calculating the sum of sum of digits
// of sq
int sum_digits = 0;
while (sq != 0) {
sum_digits = sum_digits + sq % 10;
sq = sq / 10;
}
return (sum_digits == x);
}
// Driver Code
int main(void)
{
// Printing Neon Numbers upto 10000
for (int i = 1; i <= 1000000; i++)
if (checkNeon(i))
cout << i << " ";
}
OUTPUT:-1 9
MAGIC NUMBER
refered doc:-"https://www.geeksforgeeks.org/check-number-magic-recursive-sum-digits-1/"
#include<iostream>
using namespace std;
void isMagic(int n)
{
int sum = 0,v=n;
// Note that the loop continues
// if n is 0 and sum is non-zero.
// It stops when n becomes 0 and
// sum becomes single digit.
while (n > 0 || sum > 9)
{
if (n == 0)
{
n = sum;
sum = 0;
}
sum += n % 10;
n /= 10;
}
// Return true if sum becomes 1.
if(sum == 1)
cout<<v<<" is a magic number"<<endl;
else
cout<<v<<" is not a magic number"<<endl;
}
// Driver code
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
isMagic(n);
}
}
INPUT
3
50113
1234
12345
OUTPUT
50113 is a magic number
1234 is a magic number
12345 is not a magic number