c++ 用梯形公式计算sinπx在0到1上的积分

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/03 01:36:59
c++ 用梯形公式计算sinπx在0到1上的积分

c++ 用梯形公式计算sinπx在0到1上的积分
c++ 用梯形公式计算sinπx在0到1上的积分

c++ 用梯形公式计算sinπx在0到1上的积分
一楼程序没有错,但是不是题目里写的梯形公式,而是矩形公式.所以,正确的写法应该是:
#include
#include
#define PAI 3.141592653589793
#define DT 0.00000001
double f(double x)
{
return sin(x*PAI);
}
using namespace std;
void main()
{
double x=0,s=0;
double last_fx = f(x);
double new_fx = 0;
while(x