首页 > 编程语言 > 详细

生成随机数(C++)

时间:2019-12-25 01:43:25      阅读:121      评论:0      收藏:0      [点我收藏+]
// generate random number

#include <iostream>
#include <iomanip>
#include <cstdlib> // contains function prototype for rand()

using namespace std;
int main()
{
    for (int i = 1; i <= 20; i++) // loop for 20 times
    {
        cout << setw(10) << 1 + rand()%6; // generate numbers between 1 and 6
        if (i%5 == 0) // if have 5 numbers
        {
            cout << endl; // return the nextline

        }

    }


    return 0;
}

技术分享图片

生成随机数(C++)

原文:https://www.cnblogs.com/zijidefengge/p/12094368.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!