📄 trapezoid1.cpp
字号:
//Trapezoid method of Integration
//This is the definite step version of c++
#include <iostream.h>
#include <math.h>
int N; //ensure the step
//-----------integrated fuction-------------
double f(double x)
{
return exp(x)/(1+x*x);
}
//------------------------------------------
//-----------definite step version----------
double trapezoid(double a,double b,double (*f)(double))
{
double h=(b-a)/N;
double x=b;
double trap=f(x);
x=a;
trap+=f(x);
trap/=2;
for(int i=1;i<N;i++)
{
x=a+i*h;
trap+=f(x);
}
trap*=h;
return trap;
}
//------------------------------------------
//-----------------main---------------------
void main()
{
double x,y;
cout<<"enter the lower limit,upper limit & N"<<endl;
cin>>x>>y>>N;
cout<<"The Integration(T method): "<<trapezoid(x,y,f)<<endl;
}
//------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -