求高手帮写一个代码,编程语言不限!!
发布网友
发布时间:2022-06-02 02:40
我来回答
共1个回答
热心网友
时间:2023-10-25 23:07
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 40
int main(int argc, char* argv[])
{
int a[N]={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};
int flag[N]={0},b[40];
srand(time(NULL));
for(int i=0;i<40;i++)
{
int index=rand()%N;
if(flag[index]==0)
{
b[i]=a[index];
flag[index]=1;
}
else
i--;
}
for(i=0;i<40;i++)
{
printf("%d ",b[i]);
printf("\n");
}
system("pause");
return 0;
}