1、二级等级考试C语言机试题二OOO年九月份二级等级考试C语言机试题第一题修改部分给定程序MODI1.C中函数fun的功能是:将仅在字符串s中出现而不在字符串t中出现的字符,和仅在字符串t中出现而不在字符串s中出现的字符,构成一个新字符串放在u中,u中的字符按原字符串字符顺序排列,不去掉重复字符。例如:当s=”AABCDE”, t=”BDFGG”时,u中的字符串为:”AACEFGG”。请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include #include void fun (char *s, char
2、*t, char *u) int i, j, sl, tl, k, ul=0; sl = strlen(s); tl = strlen(t); for (i=0; isl; i+) for (j=0; j=tl) for (k=0; k=ul)/*found*/ uk+ = si; uul = 0;main() char s100, t100, u100; clrscr(); printf(nPlease enter string s:); scanf(%s, s); printf(nPlease enter string t:); scanf(%s, t); fun(s, t, u); pr
3、intf(The result is: %sn, u);设计部分函数fun的功能是:把a数组中的n个数和b数组中逆序的n个数一一对应相加、求平方,结果存放在C数组中。例如:若a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8,调用该函数后,c中存放在数据是81、64、81、100、100。注意:部分源程序存在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include #include void fun(int a, int b, int c, int n)main() int i, a100=1,3,5
4、,7,8, b100=2,3,4,5,8, c100; clrscr(); fun(a, b, c, 5); printf(The result is: ); for (i=0; i5; i+) printf(%d , ci); printf(n); NONO();NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int a100, b100, c100, i, j ; rf = fopen(in.dat, r) ; wf = fopen(bc07.dat,w) ; for(i = 0 ; i 5 ; i+) for(j
5、= 0 ; j 5 ; j+) fscanf(rf, %d, &aj) ; for(j = 0 ; j 5 ; j+) fscanf(rf, %d, &bj) ; fun(a, b, c, 5) ; for(j = 0 ; j 5 ; j+) fprintf(wf, %d , cj) ; fprintf(wf, n) ; fclose(rf) ; fclose(wf) ;第二题修改部分给定程序MODI1.C中函数fun的功能是:将未在字符串s中出现、而在字符串t中出现的字符,形成一个新的字符串放在u中,u中字符按原符串中字符顺序排列,但去掉重复字符。 例如:当s=”ABCDE”,t=”BDFG
6、G”时,u中的字符为:“FG”。请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行而删行,也不得更改程序的结构!#include #include #include void fun (char *s, char *t, char *u) int i, j, sl, tl, k, ul=0; sl = strlen(s); tl = strlen(t); for (i=0; itl; i+) for (j=0; j=sl) for (k=0; kul; k+) if (ti = uk) break;/*found*/ if (kul) uul+ = ti; /
7、*found*/ *u = 0;main() char s100, t100, u100; 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: %sn, u);设计部分函数fun的功能是:把a数组中的n个数,和b数组中逆序的n个数一一相应相乘、求平方,结果存在C数组中。例如:当a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8。调用该函数后,C中存放
8、的数据是:64、225、400、441、256。注意:部分源程序存在文件PROGI.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include #include void fun(int a, int b, int c, int n)main() int i, a100=1,3,5,7,8, b100=2,3,4,5,8, c100; clrscr(); fun(a, b, c, 5); printf(The result is: ); for (i=0; i5; i+) printf(%d , ci); printf(n); NONO(
9、);NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int a100, b100, c100, i, j ; rf = fopen(in.dat, r) ; wf = fopen(bc06.dat,w) ; for(i = 0 ; i 5 ; i+) for(j = 0 ; j 5 ; j+) fscanf(rf, %d, &aj) ; for(j = 0 ; j 5 ; j+) fscanf(rf, %d, &bj) ; fun(a, b, c, 5) ; for(j = 0 ; j 5 ; j+) fprintf(w
10、f, %d , cj) ; fprintf(wf, n) ; fclose(rf) ; fclose(wf) ;第三题修改部分给定程序MODI1.C中函数fun的功能是:将既在字符串s中出现又在字符串t中出现的字符构成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符。例如:当s=”ABBCDE”, t=”BDFG”时,u中字符串为:”BBD”。请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include #include void fun (char *s, char *t, cha
11、r *u) int i, j, sl, tl; sl = strlen(s); tl = strlen(t); for (i=0; isl; i+) for (j=0; j=tl) *u+ = si; /*found*/ *u = 0;main() char s100, t100, u100; 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: %sn, u);设计部分
12、函数fun的功能是:把a数组中的n个数和b数组中逆序的n个数一一相应相乘,结果存在c数组中。例如:当a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8。调用该函数后,c中存放的数据是:8、15、20、21、16。注意:部分源程序存在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你的若干语句。#include #include void fun(int a, int b, int c, int n)main() int i, a100=1,3,5,7,8, b100=2,3,4,5,8, c100; clrscr(); fun
13、(a, b, c, 5); printf(The result is: ); for (i=0; i5; i+) printf(%d , ci); printf(n); NONO();NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int a100, b100, c100, i, j ; rf = fopen(in.dat, r) ; wf = fopen(bc03.dat,w) ; for(i = 0 ; i 5 ; i+) for(j = 0 ; j 5 ; j+) fscanf(rf, %d, &aj) ; for
14、(j = 0 ; j 5 ; j+) fscanf(rf, %d, &bj) ; fun(a, b, c, 5) ; for(j = 0 ; j 5 ; j+) fprintf(wf, %d , cj) ; fprintf(wf, n) ; fclose(rf) ; fclose(wf) ;第四题修改部分给定程序MODI1.C中函数fun的功能是:将仅在字符串S中出现、而不在字符串t中出现的字符,和仅在字符t中出现、而不在字符串s中出现的字符,构成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,但去掉重复字符。例如,当s=”AABCDE”,t=”BDFGG”时,u中的字符串为:”AC
15、EFG”。请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include #include /*found*/void fun (char s, char t, char u) int i, j, sl, tl, k, ul=0; sl = strlen(s); tl = strlen(t); for (i=0; isl; i+) for (j=0; j=tl) for (k=0; k=ul) uul+ = si; for (i=0; itl; i+) for (j=0; jsl) for (k=0; k=u
16、l) uul+ = ti; uul = 0;main() char s100, t100, u100; 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: %sn, u);设计部分函数fun的功能是:把a数组中的n个数的平方值,与b数组中逆序的n个数的平方值一一对应相减,结果存放在C数组中。例如:当a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8。
17、调用该函数后,C中存放的数据是:-63、-16、9、40、60。注意:部分源程序存在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号填入你编写的若干语句。#include #include void fun(int a, int b, int c, int n)main() int i, a100=1,3,5,7,8, b100=2,3,4,5,8, c100; clrscr(); fun(a, b, c, 5); printf(The result is: ); for (i=0; i5; i+) printf(%d , ci); printf(n)
18、; NONO();NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int a100, b100, c100, i, j ; rf = fopen(in.dat, r) ; wf = fopen(bc08.dat,w) ; for(i = 0 ; i 5 ; i+) for(j = 0 ; j 5 ; j+) fscanf(rf, %d, &aj) ; for(j = 0 ; j 5 ; j+) fscanf(rf, %d, &bj) ; fun(a, b, c, 5) ; for(j = 0 ; j 5 ; j+) fp
19、rintf(wf, %d , cj) ; fprintf(wf, n) ; fclose(rf) ; fclose(wf) ;第五题修改部分给定程序MODi1.G中函数fun的功能是:将在字符串s中出现、而未在字符串t中出现的字符构成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,但去掉重复字段。例如,当S=”AABCDE”, t=”BDFG”时,u中字符的串为:“ACE”。请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include #include void fun (char *s, cha
20、r *t, char *u) int i, j, k, sl, tl, ul=0; sl = strlen(s); tl = strlen(t); for (i=0; isl; i+) for (j=0; jtl) for (k=0; kul; k+) if (si = uk) break;/*found*/ if (kul) uul+ = si; uul = 0;main() char s100, t100, u100; clrscr(); printf(nPlease enter string s:); scanf(%s, s); printf(nPlease enter string t
21、:); scanf(%s, t); fun(s, t, u); printf(The result is: %sn, u);设计部分函数fun的功能是:把a数组中的n个数,和b数组中逆序的n个数一一对应相减、求平方,结果存在c数组中。例如:当a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8。调用该函数后,C中存放的数据是:49、4、1、16、36。注意:部分源程序存在文件PROGI.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include #include void fun(int a, int b, int c,
22、 int n)main() int i, a100=1,3,5,7,8, b100=2,3,4,5,8, c100; clrscr(); fun(a, b, c, 5); printf(The result is: ); for (i=0; i5; i+) printf(%d , ci); printf(n); NONO();NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int a100, b100, c100, i, j ; rf = fopen(in.dat, r) ; wf = fopen(bc05.dat,w)
23、 ; for(i = 0 ; i 5 ; i+) for(j = 0 ; j 5 ; j+) fscanf(rf, %d, &aj) ; for(j = 0 ; j 5 ; j+) fscanf(rf, %d, &bj) ; fun(a, b, c, 5) ; for(j = 0 ; j 5 ; j+) fprintf(wf, %d , cj) ; fprintf(wf, n) ; fclose(rf) ; fclose(wf) ;第六题修改部分给定程序MODI1.C中函数fun的功能是:将未在字符串s中出现,而在字符串t中出现的字符,构成一个新的字符串放在u中,u中字符按原字符串中字符的顺序
24、的逆序排列,不去掉重复字符。例如,当s=”ABCDE”, t=”BDFGG”时,u中的字符串为:“GGF”。请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include #include void fun (char *s, char *t, char *u) int i, j, sl, tl, ul; char r, *up=u; sl = strlen(s); tl = strlen(t); for (i=0; itl; i+) for (j=0; j=sl) *u+ = ti; /*found*/ u
25、 = 0; ul = strlen(up);/*found*/ for (i=0; iul; i+) r = upi; upi = upul-1-i; upul-1-i = r;main() char s100, t100, u100; 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: %sn, u);设计部分函数fun的功能是:把a数组中的n个数、和b数组中逆序的n个数一一对相应上减的结果,与a数组中的n个数、和b数组中逆序的n个数一一对应相加的结果相乘,结果存在c数组中。例如:当a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8。调用该函数后,C中存放的数据是:-63、-16、9、40、60
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1