fig.10.cpp

来自「用于交通流研究的Wolfram模型的程序」· C++ 代码 · 共 43 行

CPP
43
字号
//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 + =
减小字号Ctrl + -
显示快捷键?