⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig.10.cpp

📁 用于交通流研究的Wolfram模型的程序
💻 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 + -