计算机二级c语言机试试题库
第01套:给定程序的功能是调用fun函数建立班级通讯录。通讯录中记录每位学生的编号、姓名和电话号码。班级的人数和学生的信息从键盘读入,每个人的信息作为一个数据块写到名为myfile5.dat的二进制文件中。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!给定源程序:#include #include #define N 5ty edef st uctint num cha name 10 cha tel 10 oid chec found int fun 1 std found f int i if f fo en myfile5.dat , N LL etu n 0 intf n ut ut data to file n fo i 0 i#include oid fun cha s, cha t int i, sl sl st len s found fo i 0 ioid fun int a, int , lon c main int a, lon c oid N N intf ¢n ut a, ¥ scanf d,d , a, fun a, , c intf he esult is¥ d n , c N N oid N N 函数用于打开文件,入数据,调用函数,出数据,关闭文件。 ¡¢L f, f int i, a, lon c f fo en c¥ test in.dat , f fo en c¥ test out.dat , fo i 0 i oid fun int a, int , lon c c a 10 1000 10 100 a10 10 10 main int a, lon c intf ¢n ut a, ¥ scanf d,d , a, fun a, , c intf he esult is¥ d n , c N N N N 函数用于打开文件,入数据,调用函数,出数据,关闭文件。 ¡¢L f, f int i, a, lon c f fo en c¥ test in.dat , f fo en c¥ test out.dat , fo i 0 i #include #include oid W ite e£t ¡¢L oid ead e£t ¡¢L main ¡¢L f if f fo en myfile .t£t , N LL intf o en fail n e£it 0 W ite e£t f fclose f if f fo en myfile .t£t , N LL intf o en fail n e£it 0 ead e£t f fclose f found oid W ite e£t ¡¢L 1 cha st 81 intf n nte st in ith 1 to end ¥ n ets st hile st cm st , 1 0 found f uts ,f f uts n ,f ets st oid ead e£t ¡¢L f cha st 81 intf nead file and out ut to sc een ¥ n f ets st ,81,f hile feof f found intf s , f ets st ,81,f currency1'“«:'fifl是把键盘 入的内容写到 定的文件中。程序中·处fi填 ¶的内容,使程序能行出正确的结果。第一处:fifl填写文件¯的”»名,在¨个函数中,的语句f uts n ,f 分析 知:由于文件¯»f 在函数体没定过, 处¿填 f 或f 。第二处:通过 hile循环语句,把键盘 入的内容,fi写入到 定的文件中,键盘 入的内容存入st »中, ,处¿填写st 。第·处:fi把存入文件中的内容,¸从文件中读出且存入 »st 中,最 在屏幕显示出´, , 处¿填写st 。考源程序:c¥ e£am 0001 L 考 lan 1.c请 程序 到考生文件夹中, 行¨个程序 得到正确的结果。给定程序 ¢1.C中函数fun的功能是¥从低位开始取出长ø型»s中奇数位的数, 次构 一个æ数放在t中。高位仍在高位,低位仍在低位。,s中的数为:7§5 1 ,t中的数为:75 1。请改正程序中的Ø,使能得出正确的结果。注意:不fi改ºmain函数,不得增行或删行,也不得更改程序的结构!给定源程序:#include found oid fun lon s, lon t lon sl 10 t s 10 hile s > 0 s s 100 t s10 sl t found sl sl 100 main lon s, t intf n lease ente s¥ scanf ld , s fun s, t intf he esult is¥ ld n , t currency1'“«:第一处:在函数fun中使用 t,在函数定 没使用 t, ¿改为: oid fun lon s,lon t 。第二处:每循环一次,sl的值 乘10, ¿改为:sl sl 10 。考源程序:c¥ e£am 0001 L 考 modi1.c请 程序 到考生文件夹中, 行¨个程序 得到正确的结果。函数fun的功能是: 个位数的正ø数a、 并ß 一个ø数放在c中。并的 是: a数的 位和个位数 次放在c数的个位和百位 , 数的 位和个位数 次放在c数的千位和 位 。,a 5, 1 ,调用 函数 ,c 15 。注意¥ 部分源程序存在文件 G1.C中。数据文件¢N. A 中的数据不得修改。请勿改º主函数main和其函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。给定源程序:#include oid fun int a, int , lon c main int a, lon c oid N N intf ¢n ut a, ¥ scanf d,d , a, fun a, , c intf he esult is¥ ld n , c N N oid N N 函数用于打开文件,入数据,调用函数,出数据,关闭文件。 ¡¢L f, f int i, a, lon c f fo en c¥ test in.dat , f fo en c¥ test out.dat , fo i 0 i oid fun int a, int , lon c c 10 1000 a10 100 10 10 a 10 main int a, lon c intf ¢n ut a, ¥ scanf d,d , a, fun a, , c intf he esult is¥ ld n , c N N N N 函数用于打开文件,入数据,调用函数,出数据,关闭文件。 ¡¢L f, f int i, a, lon c f fo en c¥ test in.dat , f fo en c¥ test out.dat , fo i 0 i #include int fun cha fname ¡¢L f int i,n float £ if f fo en fname, N LL etu n 0 fo i 1 i#include fun int n, int a int i, j, , t fo j 0 ja i found t i if j t a j a j a a t uta int n, int int i fo i 1 i oid fun int a, int , lon c main int a, lon c oid N N intf ¢n ut a, ¥ scanf d,d , a, fun a, , c intf he esult is¥ ld n , c N N oid N N 函数用于打开文件,入数据,调用函数,出数据,关闭文件。 ¡¢L f, f int i, a, lon c f fo en c¥ test in.dat , f fo en c¥ test out.dat , fo i 0 i oid fun int a, int , lon c c 10 1000 a10 100 10 10 a 10 main int a, lon c intf ¢n ut a, ¥ scanf d,d , a, fun a, , c intf he esult is¥ ld n , c N N N N 函数用于打开文件,入数据,调用函数,出数据,关闭文件。 ¡¢L f, f int i, a, lon c f fo en c¥ test in.dat , f fo en c¥ test out.dat , fo i 0 i #include int fun cha sou ce, cha ta et ¡¢L fs, ft cha ch found if fs fo en sou ce, 1 N LL etu n 0 if ft fo en ta et, N LL etu n 0 intf n h