如何运用time函数和srand函数生成随机数,来个代码,

学习 时间:2026-06-06 01:11:17 阅读:9309
如何运用time函数和srand函数生成随机数,来个代码,

最佳回答

坚定的鸡

端庄的小蘑菇

2026-06-06 01:11:17

#include #include //srand()、rand()#include //time();#include #define N 50int main(){int n;srand((unsigned)time(NULL));//设置随机数种子while (1){n = (rand() % 10) + 1 ;//产生1~10的随机数//rand()产生的是一个很大的数,对其求余就可以达到限定范围的目的printf("%d ",n);getch();}return 0;}

最新回答共有2条回答

  • 谦让的太阳
    回复
    2026-06-06 01:11:17

    #include #include //srand()、rand()#include //time();#include #define N 50int main(){int n;srand((unsigned)time(NULL));//设置随机数种子while (1){n = (rand() % 10) + 1 ;//产生1~10的随机数//rand()产生的是一个很大的数,对其求余就可以达到限定范围的目的printf("%d ",n);getch();}return 0;}

上一篇 火星上有生命吗?

下一篇 一道非谓语的英语题40.------- for the work,he went to sleep at ease.A.