c++随机以4行5列的形式输出20个1~100之间的整数,数值之间尽量有分隔。该怎么编写?
用rand()函数产生随机数
#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