调试通过,N为从0到1分成的矩形的个数
#include "math.h"
void main()
{
double N = 10000;
double s=0;
scanf("%f",&N);
for (int i=1;i<=N;i++)
{
s = s+(1+pow(i/N,2))*(1/N);
}
printf("%f",s);
}
刚才没看清,你要的是梯形,上述是矩形,梯形算法如下:
#include "math.h"
void main()
{
double N = 10000;
double s=0;
scanf("%f",&N);
for (int i=0;i
s = s+(1+pow(i/N,2)+1+pow((i+1)/N,2))*(1/(2*N));
}
printf("%f",s);
}