2011年3月二级C语言上机100题_新_已识别

举报
资源描述
上 机 题 库第一部分填空题注意:源程序存放在考生文件夹下的BLANK1.C中。1.不得增行或删行,也不得更改程序的结构!2,请在程序下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。L整蠹蠹,盘的功能是:计算出带有头接点的单向链表中各结点数据域之和作为函数值返回。#inc lud e inc lud e d efine N 8typed ef struc t list int d a ta;struc t list*next;SLI ST;SLI ST*c rea tlist(int*);void outlist(SLI ST*);int fun(SLI ST*h)SLI ST*p;int s=0;p=h-next;while(p)/s+=p-_1_;d a tap=p-_2_;nextreturn s;)ma in()SLI ST*hea d;int a N=12,87,45,32,91,16,20,48);hea d=c rea tlist(a);outlist(hea d);printf(nsum=%d n”,fun(_3_);hea d)SLI ST*c rea tlist(int a)SLI ST*h,*p,*q;int i;h=p=(SLI ST*)ma lloc(sizeof(SLI ST);for(i=0;id a ta=a i;p-next=q;p=q;p-next=O;return h;)void outlist(S L I S T *h)S L I S T *p;p=h-next;if(p=N U L L)printf(z,T he list is N U L L!n);else printf(/znH ead );do printf(-%d”,p-data);p=p-next;while(p!=N U L L);printf(-E ndn);)2.给定程序中,函数F U N的功能是:求出形参SS所指字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中工有M个字符串,且串长 以ttincludeinclude#define#definevoid fun(char int i,j,52 0(*ss)N)k=0,n,m,len;for(i=0;i n)MNn=len;k=_ 1 _;ifor(i=0;i=0;j)lenssi m-=ssi j;for(j=0;j n-len;j+)ssE ij=3;*)m a i n()char sM N=shanghai,guangzhou,beijing,tianjing,cchongqing;int i;printf(z,nT he original strings are:n);for(i=0;i M;i+)printf(%sn,ssi);printf(n);fun(ss);printf(z,nT he result:nz,);for(i=0;i M;i+)printf(%sn,ssi);3 .人员记录由编号和出生年,月,日组成,N名人员的数据已在主函数中存入结构体数组std且编号唯一。函 数f u n的功能是;找出指定编号人员的数据,作为函数值返回,有主函数输出,若指定编号不存在,返回数据中的编号为空串。itinclude include ttdefine N 8typedef struct char num1 0;int year,month,day;S T U;_1 _ fun(S T U *std,char*num)S T U int i;S T U a=,9 9 9 9,9 9,9 9;for(i=0;i N;i+)if(s t r c m p(2,num)=0 )stdi.numreturn(_3);stdireturn a;)main()S T U stdN =rilllir,1 9 8 4,2,1 5,2 2 2 2 2 2 ,1 9 8 3,9,2 1,3 3 3 3 3 3 ,1 9 8 4,9,1,“4 4 4 4 4 4”,1 9 8 3,7,1 5,“5 5 5 5 5 5,1 9 8 4,9,2 8,6 6 6 6 6 6”,1 9 8 3,1 1,1 5,“7 7 7 7 7 7”,1 9 8 3,6,2 2,8 8 8 8 8 8”,1 9 8 4,8,1 9;S T U p;char n1 0=6 6 6 6 6 6”;p=fun(std,n);if(p.num0=0)printf(z,nN ot found!n);else printf(XnS ucceed!n );printf(%s%d-%d-%dn,/,p.num,p.year,p.month,p.day);)4 .给定程序中已建立一个带有头结点的单向链表,链表中的各结点按数据域递增有序链接。函数f u n的功能:删除链表中数据域值相同的结点,使之保留一个。ttinclude ttinclude#define N 8typed ef struc t list int d a ta;struc t list*next;SLI ST;void fun(SLI ST*h)SLI ST*p,*q;p=h-next;if(p!=NULL)q=p-next;while(q!=NULL)if(p-d a ta=q-d a ta)p-next=q-next;free(_ 1_);qq=p-_ 2_;next)else P=q;q=q-_3_;next)SLI ST*c rea tlist(int*a)SLI ST*h,*p,*q;int i;h=p=(SLI ST*)ma lloc(sizeof(SLI ST);for(i=0;id a ta=a i;p-next=q;p=q;)p-next=0;return h;)void outlist(SLI ST*h)SLI ST*p;p=h-next;if(p=NULL)printf(nThe list is NULL!n);else printf(nHea d);d o printf(/z-%d,/,p-d a ta);p=p-next;while(p!=NULL);printf(-E nd n);)ma in()SLI ST*hea d;int a N=l,2,2,3,4,4,4,5);hea d=c rea tlist(a);printf(nThe list before d eleting:n);outlist(hea d);fun(hea d);printf(nT he list after deleting:n);outlist(head);5.函数f u n的功能是进行数字字符转换。若形参c h中是数字字符,9 ,贝 0 转换成9 ,T 转换成 8,2 转换成 7 9 转换成 0 ;若是其他字符则保持不变;并将转换后的结果作为函数值返回.include 1 _fun(char ch)charif(ch=O&2)ch=9 return 9,-(ch-_3 _);return ch;)main()char cl,c2;printf(nT he result:n);cl=,2 ;c2 =fun(cl);printf(,zcl=%c c2=%cn,z,cl,c2);cl=,8 ;c2 =fun(cl);printf(cl=%c c2=%cn”,cl,c2);cl=,a;c2 =fun(cl);printf(cl=%c c2=%cn,cl,c2);)O 6.给定程序中,函数fun的功能是:对形参ss所指字符串数组中的M字符串按长度由短到长进行排序。S S所指字符串数组中共有M个字符串,且串长3includeincludettdefinedefineM 5N 2 0void fun(char(*ss)N)int i,j,k,nM;char t N;for(i=0;i M;i+)ni=strlen(ssi);for(i=0;i M-l;i+)k=i;for(j=_ 1 _;j nj)k=_2 _:jif(k!=i)strcpy(t,ssi);strcpy(ssi,ssk);strcpy(ss k,_3 _);tnk=ni;main()char sM N=shanghai,guangzhou,beijing,tianjing,cchongqing;int i;printf(nT he original strings are:n);for(i=0;i M;i+)printf(%sn”,ssi);printf(n);fun(ss);printf(nT he result:n);for(i=0;K M;i+)printf(%sn,ssi);)7 .函 数 F U N 的功能是:从三个形参a,b,c中找出中间的哪个数,作为函数值返回。例如,当a=3,b=5,c=4 时,中数为 4。4 include int fun(int a,int b,int c)int t;t=(a b)?(b c?b:(a c?c:_1 ):(a c)?_2 _:(b c)?c:_3 _);return t;1.a 2.a 3.bmain()int al=3,a2=5,a3=4,r;r=fun(al,a2,a3);printf(nT he middle number is:%dn,r);)8 .给定程序中,函数F U N 的功能是:统计出带有头结点的单向链表中接点的个数,存放在形参N所指的存储单元中。ttinclude ttinclude define N 8typedef struct list int data;struct list*next;S L I S T;S L I S T *creatlist(int*a);void outlist(S L I S T *);void fun(S L I S T *h,int*n)S L I S T *p;*n=1;0p=h-next;while(p)(*n)+;p=2;p-next)ma in()SLI ST*hea d;int a N=12,87,45,32,91,16,20,48,num;hea d=c rea tlist(a);outlist(hea d);fun(h e ad,3);&numprintf Cznnumber=%d nz,,num);)SLI ST*c rea tlist(int a )SLI ST*h,*p,*q;int i;h=p=(SLI ST*)ma lloc(sizeof(SLI ST);for(i=0;id a ta=a i;p-next=q;p=q;)p-next=0;return h;)void outlist(SLI ST*h)SLI ST*p;p=h-next;if(p=NULL)printf(The list is NULL!n);else printf(nHea d );d o printf(/z-%d,z,p-d a ta);p=p-next;while(p!=NULL);printf(-E nd n);)9.给定程序的功能是:调用函数FUN将指定源文件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,失败时返回值为0 o 在复制的过程中,把复制的内容输出到终端屏幕。主函数中源文件名房子变量sfna me中,目标文件名放在变量tfna me中。inc lud e inc lud e int fun(c ha r*sourc e,c ha r*ta rget)FI LE *fs,*ft;c ha r c h;if(fs=fopen(sourc e,_1_)=NULL)rreturn 0;if(ft=fopen(ta rget,w)=NULL)return 0;printf(nThe d a ta in file:n);c h=fgetc(fs);while(!feof(_2_)fs putc ha r(c h
展开阅读全文
温馨提示:
金锄头文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
相关资源
正为您匹配相似的精品文档
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新


电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号