复合梯形法求积公式(f(x)=sinx/x)
#include \"stdio.h\"
#include \"math.h\"
void main()
{
int k;
double a,b,n,h,x;
double f,f1,f2,T,F=0.0;
printf(\"请输入a b n :\");
scanf(\"%lf%lf%lf\
h=(b-a)/n;
for(k=1;k{x=a+k*h;
f=sin(x)/x;
printf(\"\\nf=%0.7f\
F+=f;
printf(\"\\nF=%0.7f\
}
if(a!=0.0)
f1=sin(a)/a;
else(f1=1.0);
printf(\"\\nf1=%0.7f\
f2=sin(b)/b;
printf(\"\\nf2=%0.7f\
T=0.5*h*(f1+2*F+f2);
printf(\"\\nT=%0.7f\
}
复合辛普森公式(f(x)=sinx/x)
#include \"stdio.h\"
#include \"math.h\"
void main()
{
int k;
double a,b,n,h;
double x,f,f1,f2,F1=0.0,F2=0.0,S=0.0;
printf(\"请输入a b n :\");
scanf(\"%lf%lf%lf\
h=(b-a)/n;
for(k=0;k{x=a+k*h+0.5*h;
f=sin(x)/x;
printf(\"\\nf=%0.7f\
F1+=f;
printf(\"\\nF1=%0.7f\
}
for(k=1;k{f=0;
x=a+k*h;
f=sin(x)/x;
printf(\"\\nf=%0.7f\
F2+=f;
printf(\"\\nF2=%0.7f\
}
if(a!=0)
f1=sin(a)/a;
else(f1=1.0);
f2=sin(b)/b;
S=h/6.0*(f1+4*F1+2*F2+f2);
printf(\"\\nS=%0.7f\
}