我的理解是随机输入40个0到9之间的数,统计出现次数最多的三个数.不知道是不是这个意思.程序如下,后面附上结果:#include #include void main(){ time_t t; time(&t); srand(t); int r,count[10]={0}; for(int i=0;i<40;i++){r = rand() % 10;count[r]++;printf("%d\t",r); } printf("\n\n"); int max=0,pos=0; for(i=0;i<10;i++){if(max < count){ pos = i; max = count;} } printf("出现次数最多的数:%d,出现了%d次\n",pos,max); count[pos] = 0; max = pos = 0; for(i=0;i<10;i++){if(max < count){ pos = i; max = count;} } printf("出现次数第二多的数:%d,出现了%d次\n",pos,max); count[pos] = 0; max = pos = 0; for(i=0;i<10;i++){if(max < count){ pos = i; max = count;} } printf("出现次数第三多的数:%d,出现了%d次\n",pos,max);}执行结果:8
0
4
9
5
4
2
3
5
79
8
6
9
7
5
9
9
1
20
9
8
9
1
3
6
4
1
90
6
9
0
6
6
3
4
6
5出现次数最多的数:9,出现了9次出现次数第二多的数:6,出现了6次出现次数第三多的数:0,出现了4次Press any key to continue |