上 机 题 库第一部分填空题注意:源程序存放在考生文件夹下的BL ANK1.C中。1.不得增行或删行,也不得更改程序的结构!2.请在程序下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。1.给定程序中,函 数 FUN的功能是:计算出带有头接点的单向链表中各结点数据域之和作为函数值返回。include#include#define N 8typedef struct list int data;struct list*next;SL IST;SL IST*creatlist(int*);void outlist(SL IST*);int fun(SL IST*h)SL IST*p;int s=0;p=h-next;while(p)(1rlz m*mm*mm/s+=p-_ 1data/*it*found*p=p-2:next)return s;)main()SL IST*head;/*found*/int aN=12,87,45,32,91,16,20,48);head=creatlist(a);outlist(head);printf(,nsum=%dn,fun(_ 3):head)SL IST*creatlist(int a)SL IST*h,*p,*q;int i;h=p=(SL IST*)malloc(sizeof(SL IST);for(i=0;idata=ai;p-next=q;p=q;)p-next=0;return h;)void outlist(SL IST*h)SL IST*p;p=h-next;if(p=NUL L)printf(The list is NUL L!n);else printf(nHead);do printf(-%d,p-data);p=p-next;while(p!=NUL L);printf(-Endn);)2.给定程序中,函数FUN的功能是:求出形参SS所指字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中工有M 个字符串,且串长 N。#include#include#define M 5#define N 20void fun(char(*ss)N)int i,j,k=0,n,m,len;for(i=0;in)/*found*In=len;k=_ 1)for(i=0;i=0;j-)lenssim-=ssij;for(j=0;jn-len;j+)/*found*/ssiD=-3)main()char sMN=shanghai,guangzhou,beijing,tianjing,cchongqing;int i;printf(nThe original strings are:n);for(i=0;iM;i+)printf(%sn,ssi);printf(n);fun(ss);printf(nThe result:n);for(i=0;iM;i+)printf(%sn,ssi);)3.人员记录由编号和出生年,月,日组成,N 名人员的数据已在主函数中存入结构体数组std且编号唯一。函数fu n 的功能是;找出指定编号人员的数据,作为函数值返回,有主函数输出,若指定编号不存在,返回数据中的编号为空串。#include#include#define N 8typedef struct char num10;int year,month,day;STU;/*fou nd A*/1 _ fun(STU*std,char*num)STU int i;STU a=,9999,99,99);for(i=0;iN;i+)/*found*/if(s tr c m p(2,num)=0)stdi.num/*found*/return(_ 3);stdireturn a;)main()STU stdN=111111,1984,2,15,222222,1983,9,21,333333,1984,9,1,(444444,1983,7,15,555555,1984,9,28,666666,1983,11,15,777777,1983,6,22,888888,1984,8,19;STU p;char n10=666666;p=fun(std,n);if(p.num0=0)printf(nNot found!n);else printf(nSucceed!n);printf(%s%d-%d-%dn,p.num,p.year,p.month,p.day);)4.给定程序中已建立一个带有头结点的单向链表,链表中的各结点按数据域递增有序链接。函数fun的功能删除链表中数据域值相同的结点,使之保留一个。#include#include#definetypedefN 8struct list int data;struct list*next;SL IST;void fun(SL IST*h)SL IST*p,*q;p=h-next;if(p!=NUL L)q=p-next;while(q!=NUL L)if(p-data=q-data)p-next=q-next;/*m*found*/free(-1-);q/*found*Inext)elsep=q;/*found*m*/q=q-一3一;next)SL IST*creatlist(int*a)SL IST*h,*p,*q;int i;h=p=(SL IST*)malloc(sizeof(SL IST);for(i=0;idata=ai;p-next=q;p=q;)p-next=O;return h;)void outlist(SL IST*h)SL IST*p;p=h-next;if(p=NUL L)printf(nThe list is NUL L!n);else printf(nHead);do printf(-%d,p-data);p=p-next;while(p!=NUL L);printf(-Endn);)main()SL IST*head;int aN=122,3,4,4,4,5;head=creatlist(a);printf(nThe list before deleting:n);outlist(head);fun(head);printf(nThe list after deleting:n);outlist(head);5.函数fu n的功能是进行数字字符转换。若形参ch中是数字字符,0 91则。转换成9,T转换成8,2转换成7 9转换成O;若是其他字符则保持不变;并将转换后的结果作为函数值返回.#include/*found*/_ 1_ fun(char ch)char/*found*/if(ch=0&2ch-9/*found*/return 9(ch-3):return ch;O)main()char c1,c2;printf(nThe result:n);c1-2,;c2=fun(c1);printf(c1=%c c2=%cn,c1,c2);c1-8;c2=fun(c1);printf(c1=%c c2=%cn,c1,c2);c1=a;c2=fun(c1);printf(c1=%c c2=%cn,c1,c2);)6.给定程序中,函数fun的功能是:对形参ss所指字符串数蛆中的M 字符串按长度由短到长进行排序。SS所指字符串数组中共有M 个字符串,且串长 N#includeinclude#define#defineM 5N 20void fun(char(*ss)N)int i,j,k,nM;char tN;for(i=0;iM;i+)ni=strlen(ssi);for(i=0;iM-1;i+)k=i;/*found*Ifor(j=一 1一;jnO)k=_ 2 ;if(k!=i)strcpy(t,ssi);strcpy(ssi,ssk);/*found*!strcpy(ssk,3);nk=ni;)main()char sMN=shanghai,guangzhou,beijing,tianjing,cchongqing);int i;printf(nThe original strings are An);for(i=0;iM;i+)printf(%sn,ssi);printf(n);fun(ss);printf(nThe result:n);for(i=0;iM;i+)printf(%sn,ssi);)7.函 数 FUN的功能是:从三个形参a,b,c中找出中间的哪个数,作为函数值返回。例如,当a=3,b=5,c=4 时,中数为 4。include int fun(int a,int b,int c)int t;/*fou nd*/t=(ab)?(bc?b:(ac?c:1):(a c)?_ 2 _:(bc)?c:3 _);return t;1.a 2.a 3.bmain()int a1=3,a2=5,a3=4,r;r=fun(a1,a2,a3);printf(nThe middle number is:%dn,r);)8.给定程序中,函 数 FUN的功能是:统计出带有头结点的单向链表中接点的个数,存放在形参N 所指的存储单元中。#include#include#define N 8typedef struct list int data;struct list*next;SL IST;SL IST*creatlist(int*a);void outlist(SL IST*);void fun(SL IST*h,int*n)SL IST*p;/*m*m*m*fO U n d*m*m*m*/*n=1;0p=h-next;while(p)(*n)+;/*found*/p=2;p-next)main()SL IST*head;int aN=12,87,45,32,91,16,20,48,num;head=creatlist(a);outlist(head);/*found*/fu n(h e a d,3):&numprintf(nnumber=%dn,num);)SL IST*creatlist(int a)SL IST*h,*p,*q;int i;h=p=(SL IST*)malloc(sizeof(SL IST);for(i=0;idata=ai;p-next=q;p=q;p-next=O;return h;)void outlist(SL IST*h)SL IST*p;p=h-next;if(p=NUL L)printf(The list is NUL L!n);else printf(nHead);do printf(-%d,p-data);p=p-next;while(p!=NUL L);printf(-Endn);)9.给定程序的功能是:调用函数FUN将指定源文件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,失败时返回值为0。在复制的过程中,把复制的内容输出到终端屏幕。主函数中源文件名房子变量sfname中,目标文件名放在变量tfname中。#include#include int fun(char*source,char*target)FIL E char ch;/*found*/if(fs=fopen(source,_ 1_)=NUL L)rreturn 0;if(ft=fopen(target,w)=NUL L)return 0;printf(nThe data in file An);ch=fgetc(fs);:*fc I cZ*while(!feof(2)fs putchar(ch);:*fci 1cz4*/fputc(ch,3一);ftch=fgetc(fs);)fclose(fs);fclose(ft);printf(nn);return 1;)main()char sfname20=myfile1,tfname20=myfile2;FIL E*myf