?? d6r10.cpp
字號:
# include <iostream.h>
# include <math.h>
# include <iomanip.h>
void main()
{
//program d6r10
//driver for routine irbit1
//calculate distribution of runs of zeros
int nbin,ntries,iseed,i,j,iflg,ipts,n;
double delay[16];
nbin = 15;
ntries = 10000;
iseed = 12345;
for (i = 1; i<=nbin; i++)
{
delay[i] = 0.0;
}
ipts = 0;
for (i = 1; i<=ntries; i++)
{
if (irbit1(iseed) == 1)
{
ipts = ipts + 1;
iflg = 0;
for (j = 1; j<=nbin; j++)
{
if ((irbit1(iseed) == 1) && (iflg == 0))
{
iflg = 1;
delay[j] = delay[j] + 1.0;
}
}
}
}
cout<<"Distribution of runs of n zeros"<<endl;
cout<<" n probability expected"<<endl;
cout<<setprecision(6)<<setiosflags(ios::fixed);
for (n = 1 ; n<=nbin; n++)
{
cout<<setw(5)<<n - 1;
cout<<setw(15)<<delay[n] / double(ipts);
cout<<setw(15)<<(1.0/ pow(2,n))<<endl;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -