📄 ex04-06.cpp
字号:
//EX04-07.cpp
#include <iostream.h> //cout,cin
#include <math.h> // exp()
#include <iomanip.h> // setw()
#include <conio.h> // getch()
float root(float x);
void main()
{ float xl,xu,xr; //xl:lower xu:upper xr:root
int count = 0;
cout << "Enter xl,xu:"; //enter 2.9 3.4
cin >> xl >> xu;
cout << "=============================\n";
cout << "No xl xu xr\n";
cout << "=============================\n";
if (root(xl)*root(xu)<0)
{ do
{ xr = (xl + xu)/2;
count++;
if (root(xl)*root(xr)<0)
xu = xr;
if (root(xl)*root(xr)>0)
xl = xr;
cout << setw(2) << count << " "
<< setw(8) << setiosflags(ios::fixed) << setprecision(6)<< xl << " "
<< setw(8) << setiosflags(ios::fixed) << setprecision(6)<<xu << " "
<< setw(8) << setiosflags(ios::fixed) << setprecision(6)<<xr << endl;
} while (count<=5);
cout << "=============================\n";
} //for < 0
getch(); //pause
}
float root(float x)
{ return -2.1+6.2*x-3.9*x*x+0.667*x*x*x; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -