程序改错Word文档格式.docx
《程序改错Word文档格式.docx》由会员分享,可在线阅读,更多相关《程序改错Word文档格式.docx(35页珍藏版)》请在冰豆网上搜索。
='
\0'
;
i++)
if(s[i]>
0'
&
s[i]<
9'
)
/**********ERROR**********/
s[j]=s[i];
s[j]="
\0"
}
main()
charitem[80];
printf("
\nEnterastring:
"
);
gets(item);
\n\nThestringis:
\"
%s\"
\n"
item);
fun(item);
\n\nThestringofchangingis:
【改错1】
【学生答案】
【参考答案】
voidfun(char*s)
voidfun(chars[])
voidfun(chars[80])
============================================================
【改错2】
s[j]=s[i];
s[j++]=s[i];
{s[j]=s[i];
j++;
}
【改错3】
s[j]="
s[j]='
/*------------------------------------------------------
读入一个整数m(5≤m≤20),函数rnd获得m个随机整数,
函数sortpb将这m个随机整数从小到大排序。
若输入整数7,则应输出:
3101728323647。
conio.h"
voidsortpb(intn,inta[])
inti,j,p;
for(j=0;
j<
n-1;
j++)
{
p=j;
for(i=j+1;
i<
n;
i++)
if(a[p]>
a[j])p=i;
if(p==j)
{
t=a[j];
a[j]=a[p];
a[p]=t;
}
voiddoublernd()
statict=29,c=217,m=1024,r=0;
r=(r*t+c)%m;
return((double)r/m);
voidgetarr(intn,int*x)
inti;
for(i=1;
=n;
i++,x++)*x=(int)(50*rnd());
voidputarr(intn,int*z)
i++,z++)
printf("
%4d"
*z);
if(!
(i%10))printf("
);
intaa[20],n;
\nPleaseenteranintegernumberbetween5and20:
scanf("
%d"
&
n);
getarr(n,aa);
\n\nBeforesorting%dnumbers:
n);
putarr(n,aa);
sortpb(n,aa);
\nAftersorting%dnumbers:
inti,j,p;
inti,j,p,t;
【改错2】
if(a[p]>
a[i])p=i;
if(a[i]<
a[p])p=i;
【改错3】
if(p==j)
if(p!
=j)
一、程序改错
1./*------------------------------------------------------
一个5位数,判断它是不是回文数。
即12321是回文数,个
位与万位相同,十位与千位相同。
main()
longge,shi,qian;
wan,x;
scanf("
%ld"
&
x);
wan=x%10000;
qian=x%10000/1000;
shi=x%100/10;
ge=x%10;
if(ge==wan||shi==qian)
thisnumberisahuiwen\n"
else
thisnumberisnotahuiwen\n"
longge,shi,qian;
longge,shi,qian,wan,x;
wan=x%10000;
wan=x/10000;
if(ge==wan||shi==qian)
if(ge==wan&
shi==qian)
if(shi==qian&
ge==wan)
2.
用下面的和式求圆周率的近似值。
直到最后一项的绝对值
小于等于0.0001。
π/4=1-1/3+1/5-1/7....
math"
voidfun()
floats=0,t=1,i=1;
intp=1;
while(fabs(t)<
=1e-4)
s=s+t;
p=-p;
i=i+2;
t=p/i;
pi=%d\n"
s*4);
fun();
math.h"
#include<
math.h>
intp=1;
floatp=1;
floatp=1.0;
doublep=1;
double1.0;
while(fabs(t)<
while(fabs(t)>
1e-4)
while(0.0001<
fabs(t))
while(1e-4<
0.0001)
【改错4】
printf("
pi=%f\n"
pi=%lf\n"
===============