C语言实现随机生成0~100的数

#include <iostream>
#include <time.h>

int main()
{
    srand((unsigned)time(NULL));//srand()就是给rand()提供种子seed

    for (int i = 0; i < 100; i++)
    {
        int num = rand()%100;//对100取余操作
        printf("第%d次随机生成0~100的数: %d \n",i+1,num);
    }
    printf("\n");

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/chechen/p/9074824.html
今日推荐