先通过srand()设置种子,才能用rand()%n产生随机数 #include <stdio.h> #include <stdlib.h> #include <time.h> main() { int n,i; scanf("%d",&n); int numbers[n]; srand((unsigned) time(0)); //用当前时间产生种子 for(i=0;i<n;i++){ numbers[i] = rand()%200+1; //生成1-200的随机数 printf("第%d个随机数为:%d\n",i,numbers[i]); } } <