范文无忧网公文文书入党入团

如何运用二分法思想写程序扫描呢

01月18日 编辑 fanwen51.com

二分法求 sin(x)-x*x/4=0的近似解#include#includemain(){FILE *fp;int k=0;double a=1.5,b=2,x;fp=fopen("nt","w");while((b-a)>0.01){x=(a+b)/2;fprintf(fp,"\n\nk=%d ",k);fprintf(fp,"a=%10.8f ",a);fprintf(fp,"b=%10.8f ",b);fprintf(fp,"x=%10.8f ",x);fprintf(fp,"f(x)=%10.8f ",(sin(x)-x*x/4));if(sin(x)-x*x/4==0) break;elseif((sin(x)-x*x/4)*(sin(a)-a*a/4)

推荐阅读
图文推荐
栏目列表