random walk process.cpp

来自「walk random process programmed in visual」· C++ 代码 · 共 41 行

CPP
41
字号
#include "iostream.h"
#include "windows.h"
#include "math.h"

int n;
int Exp;
float xx=0;
float yy=0;
float *d=new float (Exp);
float *xx1=new float (n);
float *yy1=new float (n);


void main()
{
	float R,theta;
	cout<<"Enter number of repeating experiment\n";
	cin>>Exp;
	cout<<"Enter N\n";
	cin>>n;
	cout<<"_________________________________\n";
	for(int i=0;i<Exp;i++)
	{
		xx=0;
		yy=0;
		for(int j=0;j<n;j++)
		{
			R=(float)rand() / RAND_MAX ;
			theta=360*R;
			xx=xx+cos (theta*3.14/180);
			xx1[j]=10*xx;
			yy=yy+sin (theta*3.14/180);
			yy1[j]=10*yy;
		}
		d[i]=sqrt(pow(xx,2)+pow(yy,2));
		cout<<"d"<<i+1<<"= "<<d[i]<<endl;
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?