xdawson.cpp

来自「这是C++数值算法(第二版)的源代码,其中包含了目前一些比较常用的数值计算的算法」· C++ 代码 · 共 36 行

CPP
36
字号
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
#include "nr.h"
using namespace std;

// Driver for routine dawson

int main(void)
{
        string txt;
        int i,nval;
        DP val,x;
        ifstream fp("fncval.dat");

        if (fp.fail())
          NR::nrerror("Data file fncval.dat not found");
        getline(fp,txt);
        while (txt.find("Dawson integral")) {
          getline(fp,txt);
          if (fp.eof()) NR::nrerror("Data not found in fncval.dat");
        }
        fp >> nval;
        getline(fp,txt);
        cout << endl << "Dawson Integral" << endl << setw(9) << "x";
        cout << setw(14) << "actual" << setw(13) << "dawson(x)";
        cout << endl << endl << fixed << setprecision(6);
        for (i=0;i<nval;i++) {
          fp >> x >> val;
          cout << setw(12) << x << setw(12) << val;
          cout << setw(12) << NR::dawson(x) << endl;
        }
        return 0;
}

⌨️ 快捷键说明

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