/**
用梯形法求积分的近似值
**/
#include"stdio.h"
#include"math.h"
float seekIntegral(float a, float b, int n)
{
float f1 = 0, f2 = 0;
float s = 0;
float deta, x;
x = a;
deta = (b - a) / n;
f1 = sin(x) + x;
for (int i = 0; i < n; i++)
{
x += deta;
f2 = sin(x) + x;
s += (f2 + f1) * deta / 2;
f1 = f2;
}
return s;
}
void main()
{
float s1,s2;
s1 = seekIntegral(0, 10, 60);
s2 = seekIntegral(0, 10, 60000);
printf("%.6f\n", s1);
printf("%.6f\n", s2);
}
C语言求积分的近似值
最新推荐文章于 2021-05-18 08:17:48 发布