编程论坛
注册
登录
编程论坛
→
C++教室
随机数组
超爷
发布于 2014-11-27 17:26, 321 次点击
定义长度为20的一个数组,每个元素使用随机数来设置,输出这20个整数,要求每5个数一行
1 回复
#2
xufan
2014-11-27 21:16
程序代码:
#include
<stdio.h>
#include
<stdlib.h>
#if
_WIN32
#include
<time.h>
#else
#include
<sys/time.h>
#endif
int
main()
{
srand((
unsigned
int
)time(NULL));
for
(
int
i =
0
; i <
20
; ++i)
{
printf(
"
%d
"
, rand()%
100
);
if
((i +
1
)%
5
==
0
)
printf(
"
\n
"
);
}
return
0
;
}
1