📄
字号:
#include<iostream>
#include<math.h>
using namespace std;
#define f(x) 1/(x) //给定被积函数
void main()
{
double a,b,err=0.0001;
int n=1,i=0;
double h=0,F=0,t,t0;
cout<<"Please input a and b:\n"; //输入被积区间
cin>>a;
cin>>b;
h=(b-a)/2;
t0=h*(f(a)+f(b));
while(1)
{
for(i=1;i<=n;i++)
F+=f(a+(2*i-1)*h);
t=(t0)/2+h*F;
if(fabs(t-t0)<3*err) {cout<<"The integration is:\n"<<t<<"\n";break;}
else
{n=2*n;h=h/2;t0=t;i=1;F=0;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -