-
Notifications
You must be signed in to change notification settings - Fork 0
/
FascinatingNumber.c
156 lines (133 loc) · 2.75 KB
/
FascinatingNumber.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
144
145
146
147
148
149
150
151
152
153
154
/*
$$$$$$$\ $$\ $$\ $$\ $$$$$$$$\
$$ __$$\ $$$\ $$ | $$ | \__$$ __|
$$ | $$ |$$\ $$\ $$$$\ $$ | $$$$$$\ $$$$$$\ $$ | $$ | $$$$$$\ $$\ $$\
$$$$$$$\ |$$ | $$ | $$ $$\$$ |$$ __$$\ $$ __$$\ $$ | $$ |$$ __$$\ $$ | $$ |
$$ __$$\ $$ | $$ | $$ \$$$$ |$$ / $$ |$$$$$$$$ |$$ | $$ |$$ / $$ |$$ | $$ |
$$ | $$ |$$ | $$ | $$ |\$$$ |$$ | $$ |$$ ____|$$ | $$ |$$ | $$ |$$ | $$ |
$$$$$$$ |\$$$$$$$ |$$\ $$ | \$$ |\$$$$$$ |\$$$$$$$\ $$ | $$ |\$$$$$$ |\$$$$$$$ |
\_______/ \____$$ |$ | \__| \__| \______/ \_______|\__| \__| \______/ \____$$ |
$$\ $$ |\_/ $$\ $$ |
\$$$$$$ | \$$$$$$ |
\______/ \______/
@author Noel Toy
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int Fascinating(int num);
int main()
{
int num;
int num2,num3,temp;
char str[20];
char str1[20];
char str2[20];
printf("\nEnter the number:");
scanf("%d",&num);
temp=num;
num2=num*2;
num3=num*3;
itoa(num, str, 10);
itoa(num2,str1,10);
itoa(num3,str2,10);
strcat(str,str1);
strcat(str,str2);
num=atoi (str);
printf("\nValue:%d",num);
if(Fascinating(num))
{
printf("\nThe number %d is a Fasinating Number",temp);
}
else
{
printf("\nThe number %d is not a Fasinating Number",temp);
}
return 0;
}
int Fascinating(int num)
{
char t[20];
int count[9]={0};
int d=num;
int len;
int temp;
itoa(d,t,10);
len=strlen(t);
if(len!=9)
{
return 0;
}
while(d>0)
{
temp=d%10;
switch(temp)
{
case 1:
count[1]=count[1]+1;
if(count[1]>1)
{
return 0;
}
break;
case 2:
count[2]=count[2]+1;
if(count[2]>1)
{
return 0;
}
break;
case 3:
count[3]=count[3]+1;
if(count[3]>1)
{
return 0;
}
break;
case 4:
count[4]=count[4]+1;
if(count[4]>1)
{
return 0;
}
break;
case 5:
count[5]=count[5]+1;
if(count[5]>1)
{
return 0;
}
break;
case 6:
count[6]=count[6]+1;
if(count[6]>1)
{
return 0;
}
break;
case 7:
count[7]=count[7]+1;
if(count[7]>1)
{
return 0;
}
break;
case 8:
count[8]=count[8]+1;
if(count[8]>1)
{
return 0;
}
break;
case 9:
count[9]=count[9]+1;
if(count[9]>1)
{
return 0;
}
break;
}
d=d/10;
}
return 1;
}