求解,随机生成一组数,然后对比是否有相等的数,如果有就重新生成
随机生成一组数,然后对比是否有相等的数,如果有就重新生成不知道哪里出错了。。求帮忙解决
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
int main()
{
int num[N];
srand((unsigned int)time(NULL));
for (int i = 0; i < N; i++)
{
num[i] = rand()%12+1;
}
for (int i = 0; i < N; i++)
{
printf("%2d ",num[i]);
}
printf("\n\n");
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N-i-1; j++)
{
if (num[i] == num[j])
{
num[i] = rand() % 12 + 1;
}
}
}
for (int i = 0; i < N; i++)
{
printf("%2d ", num[i]);
}
return 0;
}