文档介绍:
全国计算机等级考试C语言――改错题
1.给定程序中fun函数的功能是:根据整型形参m的值,计算如下公式的值:
例如,若m中的值为5,则应输出0.536389。
double fun(int m)
{ double y=1.0;
int i;
/**************found**************/
for(i=2;i
/**************found**************/
y-=1/(i*i); 改为:y-=1.0/(i*i);
return(y);}
main( )
{ int n=5;
printf("\nThe result is %lf\n",fun(n));}
2.程序中fun函数功能是:将s字符串的正序和反序进行连接,形成一个新字符串放在t数组中。例如,当
s所指字符串为“ABCD”时,则t所指字符串的内容应为“ABCDDCBA”。
/************found************/
void fun (char s,char t) 改为:void fun (char *s,char *t)
{ int i,d;
d=strlen(s);
for (i=0;i
for (i=0;i
/************found************/
t[2*d-1]='\0'; } 改为:t[2*d]='\0';
main( )
{ char s[100],t[100];
printf("\nPlease enter string S:");scanf("%s",s);
fun(s,t);
printf("\nThe result is: %s\n",t); }
3.给定程序中fun函数的功能是:将s所指字符串中位于奇数位置的字符或ASCII码为偶数的字符放入t
所指数组中(规定第一个字符放在第0位中)。例如:字符串中的数据为:DDEEFF,则应输出
ABBCDDEFF。
#define N 80
void fun(char *s,char t[ ])
{ int i,j=0;
for(i=0;i
/***********found**********/
if(i%2 && s[i]%2= =0) 改为:if(i%2= =0 || s[i]%2= =0)
t[j++]=s[i];
/***********found**********/
t[i]='\0';} 改为:t[j]='\0';
main( )
{ char s[N],t[N];
printf("\nPlease enter string s:");gets(s);
fun(s,t);
printf("\nThe result is:%s\n",t);}
4.给定程序中fun函数的功能是:计算n!。例如,给n输入5,则输出120.000000。
#include
double fun(int n)
{ double result=1.0;
/************found************/
if n== 0 改为:if (n == 0)
return 1.0;
while(n >1 && n<170)
/************found************/
result *= n-- 改为:result *= n--;
return result;
}
main( )
{ int n;
printf("Input N:");
scanf("%d",&n);
printf("\n\n%d! =%lf\n\n",n,fun(n));
}
5、给定程序中fun函数的功能是:先从键盘上输入一个3行3列的矩阵的各个元素的值,然后输出主对角线元素之和。
#include
int fun()
{ int a[3][3],sum;
int i,j;
/*********found**********/
______; 改为:sum=0
for (i=0;i<3;i++)
{ for (j=0;j<3;j++)
/*********found**********/
scanf("%d",a[i][j]); 改为:scanf("%d",&a[i][j]);
}
for (i=0;i<
内容来自淘豆网www.taodocs.com转载请标明出处.