这个是找下标的思想做的,避免了goto语句,程序更加简洁
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num =0;
int count =10;
int index;
int array[10] ={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
while (num <10) {
index = arc4random_uniform(count);
if (array[index]==-1) {
array[index]==num++;
}
}
return 0;
}
|
|