-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
executable file
·191 lines (168 loc) · 4.98 KB
/
test.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TOTAL 7
#define RANGE 16
//int check()
int main()
{
FILE *fp = fopen("Results.txt", "a");
time_t clock;
int random[RANGE], finalArr[TOTAL], userArr[TOTAL], matchArr[TOTAL], flag = 0;
srand(time(&clock));
printf("Enter TOTAL numbers between 1 and %d and without duplicates please:\n\n",RANGE);
while(flag == 0 || flag == -1)
{
flag = 0;
for(int i = 0; i <= TOTAL - 1;i++)
{
do
{
scanf("%d", &userArr[i]);
if(userArr[i] < 1 || userArr[i] > RANGE)
{
printf("Re-enter a number between 1 and RANGE:\n");
}
}while(userArr[i] < 1 || userArr[i] > RANGE);
if(i==1 && userArr[0] == userArr[1])
{
flag = -1;
system("clear");
printf("Duplicate found; start over please\n\n");
break;
}
else if(i==2 && (userArr[0] == userArr[2] || userArr[1] == userArr[2]))
{
flag = -1;
system("clear");
printf("Duplicate found; start over please\n\n");
break;
}
else if(i==3 && (userArr[0] == userArr[3] || userArr[1] == userArr[3] || userArr[2] == userArr[3]))
{
flag = -1;
system("clear");
printf("Duplicate found; start over please\n\n");
break;
}
else if(i==4 && (userArr[0] == userArr[4] || userArr[1] == userArr[4] || userArr[2] == userArr[4] || userArr[3] == userArr[4]))
{
flag = -1;
system("clear");
printf("Duplicate found; start over please\n\n");
break;
}
else if(i==5 && (userArr[0] == userArr[5] || userArr[1] == userArr[5] || userArr[2] == userArr[5] || userArr[3] == userArr[5] || userArr[4] == userArr[5]))
{
flag = -1;
system("clear");
printf("Duplicate found; start over please\n\n");
break;
}
else if(i==6 && (userArr[0] == userArr[6] || userArr[1] == userArr[6] || userArr[2] == userArr[6] || userArr[3] == userArr[6] || userArr[4] == userArr[6] || userArr[5] == userArr[6]))
{
flag = -1;
system("clear");
printf("Duplicate found; start over please\n\n");
break;
}
printf("Number %d is accepted!\n",userArr[i]);
}
if (flag != -1)
{
flag = 1;
}
}
for (int i = 1; i < RANGE + 1; i++)
{
random[i-1] = i;
}
for (int i = 0; i < RANGE; i++)
{
int temp = random[i];
int rIndex = rand() % RANGE;
random[i] = random[rIndex];
random[rIndex] = temp;
}
printf("\nLottery Numbers:\nDraw unsorted: ");
for(int i=0; i <= TOTAL - 1;i++)
{
finalArr[i] = random[i];
printf(" %d ",finalArr[i]);
}
for(int i = 0; i < TOTAL - 1; i++)
{
for(int j = 0; j < TOTAL - 1 - i; j++)
{
if(finalArr[j] > finalArr[j+1])
{
int temp = finalArr[j];
finalArr[j] = finalArr[j + 1];
finalArr[j+1] = temp;
}
}
}
printf("\nDraw sorted: ");
for(int i=0; i <= TOTAL - 1;i++)
{
printf(" %d",finalArr[i]);
}
printf("\n\nUser's Numbers:\nDraw unsorted: ");
for(int i=0; i <= TOTAL - 1;i++)
{
printf(" %d ",userArr[i]);
}
for(int i = 0;i < TOTAL - 1; i++)
{
for(int j = 0; j < TOTAL - 1 - i; j++)
{
if(userArr[j] > userArr[j+1])
{
int temp = userArr[j];
userArr[j] = userArr[j + 1];
userArr[j+1] = temp;
}
}
}
printf("\nDraw sorted: ");
for(int i=0; i <= TOTAL - 1;i++)
{
printf(" %d",userArr[i]);
}
printf("\nMatching User's Numbers:\n");
for(int i = 0; i <= TOTAL - 1; i++)
{
for(int j = 0; j <= TOTAL - 1; j++)
{
if(userArr[j] == finalArr[i])
{
matchArr[i] = finalArr[i];
printf("%d ",userArr[j]);
}
}
}
fwrite("\n\nDraw Sorted: ", RANGE, 1, fp);
for(int i = 0;i <= TOTAL - 1;i++)
{
fprintf(fp," %d", finalArr[i]);
}
fwrite("\nUser's Sorted: ", RANGE, 1, fp);
for(int i = 0;i <= TOTAL - 1;i++)
{
fprintf(fp," %d", userArr[i]);
}
fwrite("\nMatching numbers: ", 23, 1, fp);
for(int i = 0;i <= TOTAL - 1;i++)
{
for(int j = 0; j <= TOTAL - 1; j++)
{
if(userArr[j] == finalArr[i])
{
fprintf(fp,"%d ", matchArr[i]);
}
}
}
printf("\n");
fclose(fp);
return 0;
}