c++随机以4行5列的形式输出20个1~100之间的整数,数值之间尽量有分隔。

c++随机以4行5列的形式输出20个1~100之间的整数,数值之间尽量有分隔。该怎么编写?

用rand()函数产生随机数

img

#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;

int main()
{
    int t,i;
    srand(time(0));
    for(i=0;i<20;i++)
    {
       
       t=rand()%100+1;
       cout<<t<<"  ";
       if((i+1)%5==0)
       cout<<endl;
    }
   system ("pause");
   return 0;  
}

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
int j, r, nloops;
unsigned int seed;

for (j = 0; j < 5; j++) 
{
    for(int i=0;i<4;i++)
    {
         r =  rand()%100;
         printf("%d\t", r);
    }
     printf("%d\r\n", r);            
}

exit(EXIT_SUCCESS);

}

83 86 77 15 15
93 35 86 92 92
49 21 62 27 27
90 59 63 26 26
40 26 72 36 36

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632