C语言32人随机抽取10人

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<time.h> 
 4 main()
 5 {
 6     int n[32]={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};
 7     int m[10]={};
 8     int a,count;
 9     m[0]=n[rand()%32];
10     srand(time(NULL));
11     int i=1,j;
12     do
13     {
14         a=rand()%32;
15         srand(time(NULL));
16         m[i]=a;
17         count=0;
18         for (j=0;j<i;j++)
19         {
20             if(m[j]==a)
21                count+=1;
22         }
23         if(count==0)
24         {
25             printf("%d\n",n[a]);
26             i++;
27         }
28     }while(i<=10);
29 }

 

posted @ 2021-05-06 23:13  油菜园12号  阅读(312)  评论(0编辑  收藏  举报