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

📄 d2r5.cpp

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

void main()
{
    //program d2r5
    //driver for routine locate
    double x,xx[101];
    int i,j,n = 100;
    //create array to be searched
    for( i = 1; i<=n; i++)
        xx[i] = exp(double(i) / 20.0) - 74.0;
    cout<<endl;
    cout<<"Result of:    j=0 indicates x too small"<<endl;
    cout<<"              j=100 indicates x too large"<<endl;
    cout<<endl;
    cout<<"   locate      j        xx[j]         xx[j+1]"<<endl;
    //for test 
	cout<<setprecision(6)<<setiosflags(ios::fixed);
    for( i = 1; i<=19; i++)
	{
        x = -100.0 + 200.0 * i / 20.0;
        locate(xx, n, x, j);
        if (j == 0)
		{ 
            cout<<setprecision(1)<<setw(8)<<x;
            cout<<setprecision(0)<<setw(8)<<j;
            cout<<setprecision(6)<<setw(15)<<"lower lim";
            cout<<setprecision(6)<<setw(15)<<xx[j + 1]<<endl;
		}
        else 
		{
			if (j == n )
			{
				cout<<setprecision(1)<<setw(8)<<x;
				cout<<setprecision(0)<<setw(8)<<j;
				cout<<setprecision(6)<<setw(15)<<xx[j];
				cout<<setprecision(6)<<setw(15)<< "upper lim"<<endl;
			}
            else
			{
				cout<<setprecision(1)<<setw(8)<<x;
				cout<<setprecision(0)<<setw(8)<<j;
				cout<<setprecision(6)<<setw(15)<<xx[j];
				cout<<setprecision(6)<<setw(15)<<xx[j + 1]<<endl;
			}
        }
    }
} 

⌨️ 快捷键说明

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