求助啊 急
出现1到100 这100个随机数的简单算法,数字不能重复出现.数字随机出现
每个数字输出一次,总共输出100个数,随机输出,这是我想到的算法,只输出54个数,缺点是时间复杂度太大
#include "stdio.h"
#include "stdlib.h"
main()
{
int arr[54] = {1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54};
int a,i,j;
for(i = 0;i<1000;i++)
{
a = random(54);
for(j = 0;j<54;j++)
{
if(a == arr[j]&& a!=0)
{
printf("%d ",arr[j]);
arr[j] = 0;
}
}
}
getch();
}