正在加载图片...
为世纪教育www.greatc.cn4月上机考试题库改错题 12、给定程序MODC中函数fn的功能是:首先把b所 指字符串中的字符按逆序存放,然后将a所指字符串中的 maino 字符和b所指字符串中的字符,按排列的顺序交叉合并到 i char s80 所指数组中,过长的剩余字符接在c所指数组的尾部。例如, printf("Enter a string 当a所指字符串中的内容为" abcdefg",b所指字符串中的内 printf("The original string: ") puts(s); 容为”1234"时,c所指数组中的内容应该为"a4b3c2 defy fun(s) 而当a所指字符串中的内容为"1234",b所指字符串中的内 printf("The string after deleted: ") puts(s): printf("nn"); F 为" abcdefo"时,c所指数组中的内容应该为"lg2f3 dcba" 请改正程序中的错误,使它能得出正确的结果 10、给定程序 MODILO中函数fn的功能是:根据以下公 注意:不要改动main函数,不得增行或删行,也不得 式求π值,并作为函数值返 更改程序的结构 例如,给指定精度的变量eps输入00005时,应当输出# Include< <stdio. h> Pi=3.140578。 #include <string. h> 1121231234 void fun( char *a, char *b, char *c) =1+-+-×-+-X-x-+-X-×-X-+ 23353573579 请改正程序中的错误,使它能得出正确结果。 j=strlen(b) 注意:不要改动main函数,不得增行或删行,也不得*事春事 found*率幸春事* 更改程序的结构 #include <math. h> i ch=b0: b0=b0: b0=ch; #include <stdio h> double fun( double eps) i double s, t, while (*al*b)4 /率布率春事事 found*率率布事率*和事事/ 体率*布布亭事率布事 found事率*布事事率事事/ while( teps) if(b) =b.c++:b++ t=tn/2*n+1), 事市率布* found中事事率序*率率事事 main( har sl[100] s2[100), t200]; printf("nEnter sI string: ") scanf("%s"sl) printf("unPlease enter a precision: ") scanf("%lf", &x); printf("neps=%f, PF%If\nn,x, fun(x)); printf("nThe result is: %sn,t) 11、给定程序MODC中函数fun的功能是:找出一个大13、给定程序MODC中函数fun的功能是:从低位开始 于形参m且紧随m的素数,并作为函数值返回 取出长整型变量s中偶数位上的数,依次构成一个新数放在 请改正程序中的错误,使它能得出正确的结果 t中。高位仍在高位低位仍在低位 注意:不要改动main函数,不得增行或删行,也不得 例如,当s中的数为:7654321时,t中的数为:642。 更改程序的结构! 请改正程序中的错误,使它能得出正确的结果 #include <stdio. h> 注意:不要改动main函数,不得增行或删行,也不得 int fun(int m) 更改程序的结构! i int i, k #include <stdio. h> for(i=m+1;;i++){ /率事率事本事事摩率 found**率枣事摩率 for(k=2; k<i; k++) 春帝率本事亭事事 found*率摩事率率事事事*率布/ long sh10:gy if(i%k=0) s/=10; break *t=s%10 率率布市事率率布布事率布 found*事布亭事事事事事亭事事事事/ /率布率亭春事事率 found*率率布事事率率和事事 SI=sI *10 Int n maino n=fun(20); printf("n=%d\n", n) printf("nPlease enter s: ) scanf("%ld", &s); fun(s, &t);宏为世纪教育 www.greatc.cn 4 月上机考试题库 改错题 3 s[i]='\0'; } main() { char s[80]; printf("Enter a string: "); gets(s); printf("The original string: "); puts(s); fun(s); printf("The string after deleted : "); puts(s);printf("\n\n"); } 10、给定程序 MODI1.C 中函数 fun 的功能是:根据以下公 式求 π 值,并作为函数值返回。 例如,给指定精度的变量 eps 输入 0.0005 时,应当输出 Pi=3.140578。 π 1 1 2 1 2 3 1 2 3 4 ─=1+ ─ + ─×─ + ─×─×─ + ─×─×─×─+…… 2 3 3 5 3 5 7 3 5 7 9 请改正程序中的错误,使它能得出正确结果。 注意:不要改动 main 函数,不得增行或删行,也不得 更改程序的结构。 #include <math.h> #include <stdio.h> double fun(double eps) { double s,t; int n=1; s=0.0; /************found************/ t=0; while( t>eps) { s+=t; t=t * n/(2*n+1); n++; } /************found************/ return(s); } main() { double x; printf("\nPlease enter a precision: "); scanf("%lf",&x); printf("\neps=%lf, Pi=%lf\n\n",x,fun(x)); } 11、给定程序 MODI1.C 中函数 fun 的功能是:找出一个大 于形参 m 且紧随 m 的素数,并作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得 更改程序的结构! #include <stdio.h> int fun(int m) { int i, k ; for (i = m + 1 ; ; i++) { for (k = 2 ; k < i ; k++) /**************found**************/ if (i % k != 0) break ; /**************found**************/ if (k < i) return(i); } } void main() { int n ; n = fun(20) ; printf("n=%d\n", n) ; } 12、给定程序 MODI1.C 中函数 fun 的功能是:首先把 b 所 指字符串中的字符按逆序存放, 然后将 a 所指字符串中的 字符和 b 所指字符串中的字符,按排列的顺序交叉合并到 c 所指数组中,过长的剩余字符接在 c 所指数组的尾部。例如, 当 a 所指字符串中的内容为"abcdefg",b 所指字符串中的内 容为"1234"时,c 所指数组中的内容应该为"a4b3c2d1efg"; 而当 a 所指字符串中的内容为"1234",b 所指字符串中的内 容 为"abcdefg"时,c 所指数组中的内容应该为"1g2f3e4dcba"。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得 更改程序的结构! #include <stdio.h> #include <string.h> void fun( char *a, char *b, char *c ) { int i , j; char ch; i = 0; j = strlen(b)-1; /************found************/ while ( i > j ) { ch = b[i]; b[i] = b[j]; b[j] = ch; i++; j--; } while ( *a || *b ) { /************found************/ If ( *a ) { *c = *a; c++; a++; } if ( *b ) { *c = *b; c++; b++; } } *c = 0; } main() { char s1[100],s2[100],t[200]; printf("\nEnter s1 string : ");scanf("%s",s1); printf("\nEnter s2 string : ");scanf("%s",s2); fun( s1, s2, t ); printf("\nThe result is : %s\n", t ); } 13、给定程序 MODI1.C 中函数 fun 的功能是:从低位开始 取出长整型变量 s 中偶数位上的数,依次构成一个新数放在 t 中。高位仍在高位,低位仍在低位。 例如,当 s 中的数为:7654321 时,t 中的数为:642。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得 更改程序的结构! #include <stdio.h> /************found************/ void fun (long s, long t) { long sl=10; s /= 10; *t = s % 10; /************found************/ while ( s < 0) { s = s/100; *t = s%10*sl + *t; sl = sl * 10; } } main() { long s, t; printf("\nPlease enter s:"); scanf("%ld", &s); fun(s, &t);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有