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

学习 时间:2026-03-30 12:52:08 阅读:3113
如何运用time函数和srand函数生成随机数,来个代码,

最佳回答

清脆的导师

俊逸的白猫

2026-03-30 12:52:08

#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-03-30 12:52:08

    #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.