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

📄 d3r5.cpp

📁 Visual C++ 常用数值算法集 源代码
💻 CPP
字号:
#include "iostream.h"
#include "math.h"

double func2(double x)
{
    return 1.0 / sqrt(x);
}

double fint2(double x)
{
    //integral of func2
    return 2.0 * sqrt(x);
}

void main()
{
    //program d3r5
    //driver for routine midpnt
    const int nmax = 10;
    double s,a = 0.0;
    double b = 1.0;
    cout<<endl;
    cout<<"integral of func2 computed with midpnt"<<endl;
	cout.precision(6);
    cout<<endl;
    cout<<"actual value of integral is"<<"  ";
    cout<<(fint2(b) - fint2(a))<<endl;
    cout<<endl;
    cout<<"    n    approx.integral"<<endl;
	cout.setf(ios::fixed|ios::right);
	for (int i = 1; i<=nmax; i++)
	{
        midpnt(a, b, s, i);
		cout.width(5);
        cout<<i;
		cout.width(15);
        cout<<s<<endl;
    }
}

⌨️ 快捷键说明

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