回复 10楼 wengbin
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
void chongf(int* ar, int d)//判断是否重复数字,如果是则重新生成一个随机数
{
for (int i = 0; i<d; i++)
{
if (ar[i] == ar[d])
{
ar[d] = rand() % 35 + 1;
i = -1;
}
}
}
int main()
{
int arr[9][19];
srand(time(0));
for (int k = 0; k < 9; k++)
{
for (int i = 0; i < 19; i++)
{
arr[k][i] = rand() % 35 + 1;
chongf(arr, i);
printf("%d\t", arr[k][i]);
}
printf("\n\n");
}
system("pause");
return 0;
}
如果是使用二维数组就不行了··这是为什么呢。