# include <stdio.h>
# include <stdlib.h>
# include <time.h>
main()
{int a[20],i,j,x;
srand((int)time(NULL));
for(i=0;i<20;i++)
{a[i]=rand()%20;
x=0;
for(j=x;j<i;j++)
{
if(a[i]==a[j])
{
a[i]=rand()%20;
j=-1;
}
}
}
for(i=0;i<20;i++)
printf("%4d",a[i]);
}
产生不同随机数
# include <stdlib.h>
# include <time.h>
main()
{int a[20],i,j,x;
srand((int)time(NULL));
for(i=0;i<20;i++)
{a[i]=rand()%20;
x=0;
for(j=x;j<i;j++)
{
if(a[i]==a[j])
{
a[i]=rand()%20;
j=-1;
}
}
}
for(i=0;i<20;i++)
printf("%4d",a[i]);
}
产生不同随机数