程序改错 联系客服

发布时间 : 星期四 文章程序改错更新完毕开始阅读e8d83ea0bd64783e08122b06

=======(答案1)======= double sum=0.0; =========或========= double sum=0;

=======(答案2)======= while( s[i] != 0 ) =========或========= while(!s[i]==0) =========或========= while(!0==s[i]) =========或========= while(s[i])

=======(答案3)======= sum/=c;

=========或========= sum=sum/c;

=======(答案4)======= return sum;

=========或========= return (sum);

第5题 (10.0分) 题号:11 难度:中 第1章 /*------------------------------------------------------ 【程序改错】

--------------------------------------------------------

功能:用下面的和式求圆周率的近似值。直到最后一项的绝对值 小于等于0.0001。

π 1 1 1 — = 1 - — + — - — + ... 4 3 5 7

------------------------------------------------------*/ #include

/**********FOUND**********/ #include fun()

{

int i=1;

/**********FOUND**********/ int s=0,t=1,p=1;

/**********FOUND**********/ while(fabs(t)<=1e-4) { s=s+t; p=-p; i=i+2; t=p/i; }

/**********FOUND**********/ printf(\} main() { fun(); } 答案:

=======(答案1)======= #include \=========或========= #include

=======(答案2)======= float s=0,t=1,p=1; =========或========= float s=0,p=1,t=1; =========或========= float p=1,s=0,t=1; =========或========= float p=1,t=1,s=0; =========或========= float t=1,p=1,s=0; =========或========= float t=1,s=0,p=1;

=======(答案3)======= while(fabs(t)>1e-4) =========或=========

while(0.00010.0001)

=======(答案4)======= printf(\

第6题 (10.0分) 题号:13 难度:中 第1章 /*------------------------------------------------------ 【程序改错】

--------------------------------------------------------

功能:求1到20的阶乘的和。

------------------------------------------------------*/ #include fun() {

int n,j;

float s=0.0,t=1.0; for(n=1;n<=20;n++) {

/**********FOUND**********/ s=1;

for(j=1;j<=n;j++)

/**********FOUND**********/ t=t*n;

/**********FOUND**********/ s+t=s; }

/**********FOUND**********/ printf(\} main() { fun(); } 答案:

=======(答案1)======= t=1;

=========或========= t=1.0;

=======(答案2)======= t= t * j ;

=========或========= t*=j;

=========或========= t=j*t;

=======(答案3)======= s= s + t ;

=========或========= s+=t;

=========或========= s=t+s;

=======(答案4)======= printf(\

第7题 (10.0分) 题号:444 难度:易 第2章 /*------------------------------------------------------ 【程序改错】

--------------------------------------------------------

功能:编写函数fun计算下列分段函数的值: x*20 x<0且x≠-3

f(x)= sin(x) 0≤x<10且x≠2及x≠3 x*x+x-1 其它

------------------------------------------------------*/

#include #include

double fun(double x) {

/**********FOUND**********/ double y

/**********FOUND**********/ if (x<0 || x!=-3.0)