您好,欢迎访问三七文档
当前位置:首页 > 幼儿/小学教育 > 小学教育 > c语言版本复合梯形法、辛普森法求积公式
复合梯形法求积公式(f(x)=sinx/x)#includestdio.h#includemath.hvoidmain(){intk;doublea,b,n,h,x;doublef,f1,f2,T,F=0.0;printf(请输入abn:);scanf(%lf%lf%lf,&a,&b,&n);h=(b-a)/n;for(k=1;kn;k++){x=a+k*h;f=sin(x)/x;printf(\nf=%0.7f,f);F+=f;printf(\nF=%0.7f,F);}if(a!=0.0)f1=sin(a)/a;else(f1=1.0);printf(\nf1=%0.7f,f1);f2=sin(b)/b;printf(\nf2=%0.7f,f2);T=0.5*h*(f1+2*F+f2);printf(\nT=%0.7f,T);}复合辛普森公式(f(x)=sinx/x)#includestdio.h#includemath.hvoidmain(){intk;doublea,b,n,h;doublex,f,f1,f2,F1=0.0,F2=0.0,S=0.0;printf(请输入abn:);scanf(%lf%lf%lf,&a,&b,&n);h=(b-a)/n;for(k=0;kn;k++){x=a+k*h+0.5*h;f=sin(x)/x;printf(\nf=%0.7f,f);F1+=f;printf(\nF1=%0.7f,F1);}for(k=1;kn;k++){f=0;x=a+k*h;f=sin(x)/x;printf(\nf=%0.7f,f);F2+=f;printf(\nF2=%0.7f,F2);}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,S);}
本文标题:c语言版本复合梯形法、辛普森法求积公式
链接地址:https://www.777doc.com/doc-3814293 .html