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

📄 xgasdev.cpp

📁 C++数值算法原书代码
💻 CPP
字号:
#include <string>
#include <iostream>
#include <iomanip>
#include "nr.h"
using namespace std;

// Driver for routine gasdev

int main(void)
{
        const int N=20,NOVER2=N/2,NPTS=10000,ISCAL=400,LLEN=50;
        int i,j,klim,idum=(-13);
        DP dd,x;
        Vec_INT dist(N+1);

        for (j=0;j<=N;j++) dist[j]=0;
        for (i=0;i<NPTS;i++) {
          x=0.25*N*NR::gasdev(idum);
          j=int(x > 0 ? x+0.5 : x-0.5);
          if ((j >= -NOVER2) && (j <= NOVER2)) ++dist[j+NOVER2];
        }
        cout << "Normally distributed deviate of " << NPTS;
        cout << " points" << endl << endl;
        cout << setw(5) << "x" << setw(11) << "p(x)";
        cout << setw(10) << "graph:" << endl << endl;
        cout << fixed << setprecision(4);
        for (j=0;j<=N;j++) {
          dd=DP(dist[j])/NPTS;
          klim=int(ISCAL*dd);
          if (klim > LLEN) klim=LLEN;
          string txt(klim,'*');
          cout << setw(8) << j/(0.25*N) << setw(9) << dd << "  ";
          cout << txt << endl;
        }
        return 0;
}

⌨️ 快捷键说明

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