计算机等级考试二级上机填空100题.pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《计算机等级考试二级上机填空100题.pdf》由会员分享,可在线阅读,更多相关《计算机等级考试二级上机填空100题.pdf(171页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、【计 算 机 等 级 考 试】二 级 上 机 南 开100题 第 一 部 分 填 空 题-注 意:源程序存放在考生文件夹下的BLANK1.C中。.【计算机等级考试】南开大学二级上机100题(一)2012年12月30 日 22:16:07【计算机等级考试】二级上机南开100题第一部分填空题注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!请在程序下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。1.0给定程序中,函数FUN的功能是:计算出带有头接点的单向链表中各结点数据域之和作为函数值返回。#include#include#define N 8t
2、ypedef struct list int data;struct list*next;SLIST;SLIST*creatlist(int*);void outlist(SLIST*);int fun(SLIST*h)SLIST*p;int s=0;p=h-next;while(p)/*found*s+=p-1data/*found*p=p-2.nextreturn s;main()SLIST*head;int aN=12,87,45,32,91,16,20,48;head=creatlist(a);outlist(head);printf(nsum=%dn,f u n(3);headSLI
3、ST*creatlist(int a)SLIST*h,*p,*q;int i;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;idata=ai;p-next=q;p=q;)p-next=O;return h;)void outlist(SLIST*h)SLIST*p;p=h-next;if(p=NULL)printf(The list is NULL!n);else printf(nHead);do printf(-%dz p-data);p=p-next;while(p!=NULL);printf(-Endn);2.给定程序中,函 数 FUN的功能是:求出形
4、参S S 所指字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中工有M 个字符串,且串长N。#include#include#defineM 5#defineN 20void fun(char(*ss)N)int i,k=0z n,mz len;for(i=0;in)/*found*n=len;k=1for(i=0;i=0;j-)lenssim-=ssij;for(j=0;jn-len;j+)/*found*ssij=3.1*1main()charsMN=shanghai,guangzhou,beijing,tianjing,cchongqing);
5、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 n
6、um10;int year;month,day;STU;1 fun(STU*std,char*num)STU int i;STU a=z9999z99z99;for(i=0;iN;i+)/*found*if(s t r c m p(2 znum)=0)di.numstreturn(3);stdireturn a;)main()STUstdN=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,22W888888”,
7、1984,89);STU p;char n10=666666;p=fun(stdzn);if(p.num0=0)printf(nNot found!n);else printf(nSucceed!n);printf(%s%d-%d-%dnzp.num,p.yeai;p.monthzp.day);4.给定程序中已建立一个带有头结点的单向链表,链表中的各结点按数据域递增有序链接。函数fu n的功能:删除链表中数据域值相同的结点,使之保留一个。#include#include#define N 8typedef struct list int data;struct list*next;SLIST;
8、void fun(SLIST*h)SLIST*p,*q;p=h-next;if(p!=NULL)q=p-next;while(q!=NULL)if(p-data=q-data)p-next=q-next;/*found*f r e e(1);q/*found*q=p-2.nextelse p=q;/*found*q=q-一3nextSLIST*creatlist(int*a)SLIST*h,*pz*q;int i;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;idata=ai;p-next=q;p=q;)p-next=O;return h;)void out
9、list(SLIST*h)SLIST*p;p=h-next;if(p=NULL)printf(nThe list is NULL!n);else%dzp-data);p=p-next;while(p!=NULL);printf(-Endn);)main()SLIST*head;int aN=lz2/2/3,4,4z4/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 的功
10、能是进行数字字符转换。若形参ch中是数字字符0夕,则U 转换成9,T 转换成8,2 转换成7 9 转换成U;若是其他字符则保持不变;并将转换后的结果作为函数值返回.#include 1 fun(char ch)charif(ch=0&2)return 9-(ch-_ 3);return ch;ch=9O main()char cl,c2;printf(nThe result:n);cl=2;c2=fun(cl);printf(cl=%c c2=%cn,cl,c2);cl=8;c2=fun(cl);printf(cl=%c c2=%cn,cl,c2);cl=a;c2=fun(cl);printf
11、(cl=%c c2=%cn,cl,c2);6.给定程序中,函数fun的功能是:对形参ss所指字符串数组中的M字符串按长度山短到长进行排序。SS所指字符串数组中共有M 个字符串,且串长N#include#include#define M 5#define N 20void fun(char(*ss)N)int i,j,k,nM;char tN;for(i=0;iM;i+)ni=strlen(ssi);for(i=0;iM-l;i+)/*found*f o r(j=1;jnj)k=2.if(k!=i)strcpy(t,ssi);strcpy(ssi,ssk);/*found*strcpy(ssk,
12、3);nk=ni;main()charsMN=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);7.函 数FUN的功能是:从三个形参a,b,c中找出中间的哪个数,作为函数值返回。例如,当a=3,b=5,c=4时,中数为4。#includeint fun(inta,int
13、 b,int c)int t;/*found*t=(ab)?(bc?b:(a c?c:1):(a c)?2.(bc)?c:3);return t;1.a 2.a 3,bmain()int al=3,a2=5,a3=4,r;r=fun(al,a2,a3);printf(nThe middle number is:%dn,r);8.给定程序中,函 数FUN的功能是:统计出带有头结点的单向链表中接点的个数,存放在形参N 所指的存储单元中。#include#include#define N 8typedef struct list int data;struct list*next;SLIST;SLI
14、ST*creatlist(int*a);void outlist(SLIST*);void fun(SLIST*h,int*n)SLIST*p;/*found*n=10p=h-next;while(p)(*n)+;/*found*P=2.P-nextmain()SLIST*head;int aN=12,87,45z32z91,16z20,48X num;head=creatlist(a);outlist(head);/*found*f u n(h e a d,3);&numprintf(nnumber=%dn,num);)SLIST*creatlist(int a)SLIST*h,*p,*q;
15、int i;h=p=(SLIST*)ma I loc(sizeof(SLIST);for(i=0;idata=ai;p-next=q;p=q;)p-next=0;return h;void outlist(SLIST*h)SLIST*p;p=h-next;if(p=NULL)printf(The list is NULL!n);else%d,p-data);p=p-next;while(p!=NULL);printf(-Endn);9.给定程序的功能是:调用函数FUN将指定源文件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,失败时返回值为O o在复制的过程中,把复制的内容输出到终端
16、屏幕。主函数中源文件名房子变量sfname中,目标文件名放在变量tfname中。#include#include int fun(char.source,char*target)FILE char ch;/*found*if(fs=fopen(source,1)=NULL)return 0;if(ft=fopen(target,w)=NULL)return 0;printf(nThe data in file:n);ch=fgetc(fs);/*found*while(!feof(2)fs putchar(ch);/*found*fputc(chz 3);ftch=fgetc(fs);fclo
17、se(fs);fclose(ft);printf(nn);return 1;main()char sfname20=myfilelztfname20=myfile2;FILE*myf;int i;char c;myf=fopen(sfnamezw);printf(nThe original data:n);for(i=l;i30;i+)c=A+rand()%25;fprintf(myf,%c,c);printf(%czc);fclose(myf);printf(nn);if(fun(sfname,tfname)printf(Succeed!);else printf(Fail!);10.给定程
18、序中,函数FUN的功能是:在形参S 所指字符串中的每个数 字 字 符 之 后 插 入 一 个*。例 如,形 参 S所 指 字 符 串为:def35adh3kjsdf7.执行结果为:def3*5*adh3*kjsdf7*#include void fun(char*s)int i,j,n;for(i=0;si!=0;i+)/*found*si=0&1 n=0;/*found*while(si+l+n!=2)n+;0for(j=i+n+l;ji;j-)/*found*sj+l=3sji=i+l;main()char s80=ba3a54cd23a;printf(nThe original stri
19、ng is:%sn,s);fun(s);printf(nThe result is:%sn,s);11.给定程序中,函数FUN的功能是:将形参STD所指结构体数组中年龄最大者的数据作为函数值返回,并 将 main函数输出。#include typedef struct char name10;int age;STD;STD fun(STD std,int n)STD max;int i;/*found*m a x=1stdOfor(i=l;in;i+)/*found*if(m ax.age 2)max=stdi;stdi-agereturn max;main()STD std5=aaaz17Z
20、,bbb46;,ccc,z18,ddd,17zeee45;STD max;max=fun(std,5);printf(nThe result:n);/*found*printf(nName:%s,Age:%dn,_3,max.age);max.name1 2.给定程序中,函 数fu n功能是:在带有头结点的单向链表中,查找数据域中为C H的结点,找到后通过函数值返回该结点在链表中所处的顺序号;若不存在值为C H的结点,函数返回0值。#include#include#define N 8typedef struct list int data;struct list*next;SLIST;SLI
21、ST*creatlist(char*);void outlist(SLIST*);int fun(SLIST*h,char ch)SLIST*p;int n=0;p=h-next;/*found*w h ile(p!=1)NULL n+;/*found*if(p-data=ch)return 2.nelse p=p-next;return 0;main()SLIST*head;int k;char ch;char aN=,m7p,g,;a,;w,z,x,;r,z,d,;head=creatlist(a);outlist(head);printf(Enter a letter:);scanf(%
22、c,&ch);/*found*k=fu n(3);head,chif(k=0)printf(nNot found!n);elseprintf(The sequence number is:%dn,k);SLIST*creatlist(char*a)SLIST*h,*p,*q;int i;h=p=(SLIST*)malloc(sizeof(SLIST);for(i=0;idata=ai;p-next=q;p=q;)p-next=O;return h;)void outlist(SLIST*h)SLIST*p;p=h-next;if(p=NULL)printf(nThe list is NULL!
23、n);else printf(nHead);do pri ntf(%c,p-data);p=p-next;while(p!=NULL);printf(-Endn);13.给定程序的功能是:从键盘输入若干行文本(每行不超过8 0个字符),写到文件myfile4.txt中,用-1作为字符串输入结素的标志。然后将文件的内容读出显示在屏幕上。文件的读写分别由自定义函数readText 和 write Text 实现.#include#include#include void Writelext(FILE*);void Readlext(FILE*);main()FILE*fp;if(fp=fopen(
24、myfile4.txt,w)=NULL)printf(open fail!n);exit(0);Writelext(fp);fclose(fp);if(fp=fopen(,myfile4.txt7r,)=NULL)printf(open fail!n);exit(0);Readlext(fp);fclose(fp);/*found*voidWritelext(FILE1 _)*fw char str81;printf(nEnter string with-1 to end:n);gets(str);while(strcmp(sti;-r,)!=O)/*found*f p u t s(2_zfw
25、);fputs(n,fw);strgets(str);void Readfext(FILE*fr)char str81;printf(nRead file and output to screen:n);fgets(str;81,fr);while(!feof(fr)/*found*printf(%s,3);fgets(str)81,fr);str14.给定程序中,函 数 FU N 的功能是:有N X N 矩阵,根据给定的m(m=N)值,将每个元素中的值均右移m 个位置,左边置为0。例如,N=3,m=2,有下列矩阵1 2 3456程序执行结果为7 8 90 0 10 0 40 0 7#incl
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机等级考试 二级 上机 填空 100
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内