-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest112.c
More file actions
63 lines (62 loc) · 1.01 KB
/
test112.c
File metadata and controls
63 lines (62 loc) · 1.01 KB
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
#include <stdio.h>
#include <stdlib.h>
int randomInt(int n)
{
return rand()%n;
}
int main()
{
int a[10],b[10],c[10],i,j,k = 0,k_count,count_element,type = 0,newtype = 1,max_times = 1,max_index = 0;
srand(time(NULL));
for(i = 0; i < 10; i++)
a[i] = randomInt(11);
for(i = 0; i < 10; i++)
printf("a[%d] = %d ",i,a[i]);
printf("\n");
for(i = 0; i < 10; i++)
{
count_element = 1;
if(i != 0)
{
for (k_count = 0; k_count < k; k_count++)
{
if (a[i] == b[k_count])
{
newtype = 0;
break;
}
}
}
if (newtype != 0)
type = 0 ;
for(j = i + 1; j < 10; j++)
{
if(a[i] == a[j])
count_element++;
}
c[k] = count_element++;
if(type == 0)
{
b[k] = a[i];
k++;
type = 1;
}
newtype = 1;
}
for(i = 0; i < k; i++)
{
if(c[i] >= max_times)
max_times = c[i];
}
for(i = 0; i < k; i++)
printf("%d -- %d ",b[i],c[i]);
printf("\n");
printf("max: ");
for(i = 0; i < k; i++)
{
if(c[i] == max_times)
printf("%d--%d ",b[i],c[i]);
}
printf("\n");
return 0;
}