#include
using namespace std; #define e 1e-6
#define f(x) (exp(x)) //定义f(x) int main() {
int i,n,a,b,k; double h,ll,l,g;
cout << \请输入要积分exp x的上下限\ cin >> a >> b;
if (a>b) k=a,a=b,b=k; //判断输入的数值是否是上下限 n=1;
h=(double)(b-a)/2; l=h*(f(a)+f(b)); do {
ll=l; g=0;
for (i=1;i<=n;i++)
g+=f((a+(2*i-1)*h)); l=(ll/2)+(h*g); n*=2; h/=2; }
while (fabs(l-ll)>e); //判断是否满足误差限e cout< 程序执行结果(拷屏): 源程序文件名: 第一天第二题1.cpp,第一天第二题2.cpp,第一天第二题3.cpp 2.将一个mxn的整型矩阵转置。 程序编制要点(知识点、程序框图): 开始 输入数组元素 输出原矩阵 按列输出即为转置矩阵 结束 源程序代码: #include class A { public: int **a; void input(); void output(); void swap(); int m,n; private: int b[100][100]; }; void A::input() { cout<<\矩阵的转置\ cout<<\ cout << \输入m n:\ cin>>m>>n; a=new int*[m]; for(int i=0;i a[i]=new int[n]; cout<<\输入\矩阵:\ for( i=0; i for(int j=0; j cout<<\ cout<<\输入矩阵A为:\} void A::output() { for(int i=0;i for(int j=0;j cout< cout< cout<<\} void A::swap() { cout<<\转置矩阵B为:\ for(int i=0;i for(int j=0;j b[j][i]=a[i][j]; } cout< for( i=0;i for(int j=0;j void main() { A a; a.input(); a.output(); a.swap(); } 程序执行结果(拷屏): 源程序文件名: 第一天第三题.cpp 3.用二分法(对分法)求方程f(x)=x3-2x-5=0在[2, 3]内的根的近似值,绝对误差要求小于0.001。(x=2.0945515) 程序编制要点(知识点、程序框图):