I want to do generate 7 different number (0-9) - first digit should not be 0- and put them into an array. Every number should be unique. I know what I did wrong but I dont know what should I do.
int arr[7], j, i;
srand(time(NULL));
for (i = 0; i < 7; i++)
{
arr[i] = rand() % 10;
if (arr[0] == 0)
arr[0] = rand() % 10;
}
for (i = 0; i < 7; i++)
{
for (j = 0; j < 7; j++)
{
if (i == j) {
j++;
}
if (arr[i] == arr[j])
arr[j] = rand() % 10;
}
}
printf("
");
for(j=0;j<7;j++)
printf("
%d ", arr[j]);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…