#include <stdio.h>
#include <stdlib.h>//srand ,rand
#include <time.h>//用到time()
int main()
{
int random=0;
int index=0;
int i=0;
int check=0;
int cmdbox[10]={201,202,203,204,205,206,207,208,209,210};//从这个数组中取数
int randbox[5]={0};//存放5个随机数
srand((unsigned) time(NULL));
while(index<5)
{
random=rand();
printf("random=%d",random);
random=random%10;
for(i=0;i<index;i++)
{
if(random==randbox[i])
{
check=1;
break;
}
else
check=0;
}
if(check==1)
continue;
else
{
randbox[index]=random%10;
index++;
}
}
printf("\n");
for(index=0;index<5;index++)
{
printf("randbox[%d]=%d\n",index,randbox[index]);
}
printf("############################\n");
for(index=0;index<5;index++)
{
printf("randbox[%d]=%d\n",index,cmdbox[randbox[index]]);
}
return 0;
}
|