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

📄 d10r12.cpp

📁 工程计算中经常用到的数值vc算法
💻 CPP
字号:
#include <math.h>
#include <iomanip.h>
#include <iostream.h>
#include <process.h>

void main()
{
    //program d10r12
    //driver for routine qroot
	int n,ntry,nroot,nflag,i,j;
	double eps,tiny,p[8],b[11],c[11],aaa,bbb;
    n = 7;
    eps = 0.000001;
    ntry = 10;
    tiny = 0.00001;
    p[1] = 10.0;    p[2] = -18.0;
    p[3] = 25.0;    p[4] = -24.0;
    p[5] = 16.0;    p[6] = -6.0;
    p[7] = 1.0;
    cout<<endl;
    cout<<setw(5)<<"P[x]=x^6-6x^5+16x^4-24x^3+25x^2-18x+10"<<endl;
    cout<<endl;
    cout<<setw(5)<<"Quadratic factors x^2+bx+c"<<endl;
    cout<<endl;
    cout<<setw(5)<<" factor       b              c"<<endl;
    nroot = 0;
	cout<<setprecision(5)<<setiosflags(ios::fixed);
    for (i = 1; i<=ntry; i++)
	{
        c[i] = 0.5 * i;
        b[i] = -0.5 * i;
        qroot(p, n, b[i], c[i], eps);
        if (nroot == 0)
		{
            cout<<setw(3)<<nroot;
            cout<<setw(15)<<b[i];
            cout<<setw(15)<<c[i]<<endl;
            nroot = 1;
		}
        else
		{
            nflag = 0;
            for (j = 1; j<=nroot; j++)
			{
                aaa = fabs(b[i] - b[j]);
                bbb = fabs(c[i] - c[j]);
                if ((aaa < tiny) && (bbb < tiny))  nflag = 1;
            }
            if (nflag == 0)
			{
                cout<< setw(3)<<nroot;
                cout<< setw(15)<<b[i];
                cout<< setw(15)<<c[i]<<endl;
                nroot = nroot + 1;
            }
		}
    }
}

⌨️ 快捷键说明

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