二级C语言上机改错题题型
main() { char s[100], t[100]; clrscr(); printf("\nPlease enter string s:"); scanf("%s", s); fun(s, t); printf("The result is: %s\n", t); }
第5题
给定程序MODI1.C中函数 fun 的功能是:将在字符串s中下标为偶数 位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原 字符串中字符出现的逆序排列。(注意0为偶数)
main() { char s[100], t[100], u[100]; clrscr(); printf("\nPlease enter string s:"); scanf("%s", s);
printf("\nPlease enter string t:"); scanf("%s", t); fun(s, t, u); printf("the result is: %s\n", u); }
全国计算机等级二级C语言上机改错题题型
第1题 给定程序MODI1.C中函数 fun 的功能是:把在字符串s中出现的每个
字符,紧随其后重复出现一次,形成一个新串放在t中,t中字符按原字 符串中字符顺序排列。
例如:当s中的字符串为:"ABAABBCCDDEE"。
则t中的字符串应为:"AABBCCDDEE"。
void fun (char *s, char *t) { int i, j, sl; sl = strlen(s); /************found************/ for (i=0, j=0; i { t[2*j] = s[i]; t[2*j +1] = s[i]; /************found************/ j--; /参考答案:j++/ } t[2*j] = '\0'; }
请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!
Modi1.c #include #include #include /************found************/
void fun (char s,char t) /参考答案:void fun (char *s,char *t)/
/************found************/ void fun (char *s, char *t, char u) /参考答案:void fun (char *s, char *t, char *u) { int i, j, sl, tl; sl = strlen(s); tl = strlen(t); for (i=0; i { for (j=0; j if (s[i] == t[j]) break; /************found************/ if (j>tl) /参考答案:if (j>=tl) *u++ = s[i]; } *u = '\0'; }
例如:当s中的字符串为:"ABCDEF"时, 则t中的字符串应为:"EECCAA"。 请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!
Modi1.c #include #include #include
void fun (char *s, char *t) { int i, j, sl; sl = strlen(s); if(sl%2)sl--; else sl-=2; /************found************/ for (i=sl, j=0; i>=0; i--) /参考答案:for (i=sl, j=0; i>=0; i-=2)/ { t[2*j] = s[i]; t[2*j +1] = s[i]; j++; } /************found************/ t[2*sl] = '\0'; /参考答案:t[2*j] = '\0';/ }
main() { char s[100], t[100]; clrscr(); printf("\nPlease enter string s:"); scanf("%s", s); fun(s, t); printf("The result is: %s\n", t); }
第4题 给定程序MODI1.C中函数 fun 的功能是:将在字符串s中下标为奇数 位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原 字符串中字符的顺序排列。(注意0为偶数) 例如:当s中的字符串为:"ABCDEF"时, 则t中的字符串应为:"BBDDFF"。 请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构! Modi1.c #include #include #include
{ int i, sl; sl = strlen(s); for (i=0; i { t[2*i] = s[i]; t[2*i+1] = s[i]; }
/************found************/
t[2*sl] = '0'; /参考答案:t[2*sl] = '\0';/
} main()
main() { char s[100], t[100];
clrscr(); printf("\nPlease enter string s:"); scanf("%s", s); fun(s, t); printf("The result is: %s\n", t); } 第3题 给定程序MODI1.C中函数 fun 的功能是:将在字符串s中下标为偶数 位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原 字符串中字符的顺序排列。(注意0为偶数) 例如:当s中的字符串为:"ABCDE"时, 则t中的字符串应为:"AACCEE"。 请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构! Modi1.c #include #include #include void fun (char *s, char *t) { int i, j, sl; sl = strlen(s); /************found************/ for (i=0, j=0; i { t[2*j] = s[i]; t[2*j +1] = s[i]; j++; } /************found************/ t[2*sl] = '\0'; /参考答案:t[2*j]='\0';/ }
void fun (char *s, char *t) { int i, j, sl; sl = strlen(s); /************found************/ if(sl%2) Sl-=2; else Sl--; /参考答案:if(sl%2) sl-=2; else sl--;/ for (i=sl, j=0; i>=0; i-=2) { t[2*j] = s[i]; t[2*j +1] = s[i]; j++; } /************found************/ t[2*sl] = '0'; /参考答案:t[2*j] = '\0';/ }
{ s[100], t[100];
clrscr();
printf("\nPlease enter string s:"); scanf("%s", s);
fun(s, t);
printf("The result is: %s\n", t);
} 第2题 给定程序MODI1.C中函数 fun 的功能是:把在字符串s中出现的每个 字符, 紧随其后重复出现一次,放在一个新串t中,t中字符按原字符串 中逆排列。 例如:当s中的字符串为:"ABCDE"时, 则t中的字符串应为:"EEDDCCBBAA"。 请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构! Modi1.c #include #include #include void fun (char *s, char *t) { int i, sl; sl = strlen(s); /************found************/ for (i=1; i { t[2*i] = s[sl-i-1]; t[2*i +1] = s[sl-i-1]; } /************found************/ t[2*sl] = '0/'; /参考答案:t[2*sl] = '\0';/ }
void fun (char *s, char *t) { /************found************/ int i, j; /参考答案:int i,j,sl;/ sl = strlen(s); for (i=0, j=0; i { if (i+1 < sl) { t[2*j] = s[i+1]; t[2*j +1] = s[i+1]; j++; } t[2*j] = s[i]; t[2*j +1] = s[i]; /************found************/ j--; /参考答案:j++;/ } t[2*sl] = '\0'; }