d9r6.cpp

来自「使用VC++编写的大量数学算法的源代码」· C++ 代码 · 共 40 行

CPP
40
字号
#include "iostream.h"

void fpoly(double x, double p[], int np)
{
	p[1] = 1.0;
	for (int j = 2; j<=np; j++)
	{
		p[j] = p[j - 1] * x;
	}
}

void main()
{
    //program d9r6
    //driver for routine fpoly
    int nval = 15;
    double dx = 0.1;
    int npoly = 5;
    double afunc[6];
	double x;
    cout<<"                   Powers of x"<<endl;
    cout<<endl;
    cout<<"   x    x^0       x^1      x^2       x^3      x^4"<<endl;
	cout.setf(ios::left);
    for (int i = 1; i<=nval; i++)
	{
        x =i * dx;
        fpoly(x, afunc, npoly);
		cout<<"  ";
		cout.width(7);
        cout<<x;
        for (int j = 1; j<=npoly; j++)
		{
			cout.width(9);
            cout<<afunc[j];
        }
        cout<<endl;
    }
}

⌨️ 快捷键说明

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