📄 fig.10.cpp
字号:
//FIG.10
#include "stdafx.h"
#include<iostream.h>
#include <stdlib.h>
#include <time.h>
int _tmain(int argc, _TCHAR* argv[])
{
int j,n,a[100],i,time_steps;
float p;
cout<<"Please enter the number of sites n: "<<endl;
cin>>n;
cout<<"Please enter time_steps: "<<endl;
cin>>time_steps;
cout<<"Please enter the probability p: "<<endl;
cin>>p;
srand( (unsigned)time( NULL ) );
/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
for(j=1;j<=time_steps;j++)
{
cout.width(4);
cout<<j<<":";
for(i=0;i<n;i++)
{
if(rand()<((RAND_MAX+1)*p-1))
{
a[i]=1;
cout<<"*";
}
else
{
a[i]=0;
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -