用C提供的随机函数生成20个0或1的数,并按每行10个显示输出。
来源:百度知道 编辑:UC知道 时间:2024/06/02 07:21:10
#include <iostream>
#include <time.h>
using namespace std;
int main( )
{
srand( time( NULL ) );
int i, t;
for ( i = 1; i <= 20; i++ )
{
t = rand()%2;
cout << t << ' ';
if ( i == 10 ) cout << endl;
}
return 0;
}
楼上兄弟用的是C++,在C语言编译器不识别.
LZ可以把cout<<t<<' '; 改成printf("%d",t);把cout<<endl;改成printf("\n");就OK了!