ImageVerifierCode 换一换
格式:DOCX , 页数:25 ,大小:20.36KB ,
资源ID:3396521      下载积分:12 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3396521.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(计算机二级考试C语言模拟题五套.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

计算机二级考试C语言模拟题五套.docx

1、计算机二级考试C语言模拟题五套题库6一、填空题给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用fun 函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下BLANK1.C中。不得增行或删行,也不得更改程序的结构!给定源程序:#include #include #define N 8typedef struct listint data;struct list *next; SLIST;void fun(SLIST *p)SLIST *t, *s;t

2、=p-next; s=p;while(t-next != NULL)s=t;/*found*/t=t-_1_;/*found*/printf( %d ,_2_);s-next=NULL;/*found*/free(_3_);SLIST *creatlist(int *a)SLIST *h,*p,*q; int i;h=p=(SLIST *)malloc(sizeof(SLIST);for(i=0; i q=(SLIST *)malloc(sizeof(SLIST);q-data=ai; p-next=q; p=q;p-next=0;return h;void outlist(SLIST *h)

3、SLIST *p;p=h-next;if (p=NULL) printf(nThe list is NULL!n);elseprintf(nHead);do printf(-%d,p-data); p=p-next; while(p!=NULL);printf(-Endn);main()SLIST *head;int aN=11,12,15,18,19,22,25,29;head=creatlist(a);printf(nOutput from head:n); outlist(head);printf(nOutput from tail: n);while (head-next != NUL

4、L)fun(head);printf(nn);printf(nOutput from head again :n); outlist(head);解题答案:/*第一空*/t=t-next;/*第二空*/printf( %d ,t-data);/*第三空*/free(t);*二、改错题:给定程序MODI1.C中函数fun的功能是:将字符串中的字符按逆序输出,但不改 变字符串中的内容。 例如,若字符串为abcd,则应输出:dcba。请改正程序中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!给定源程序:#include /*found*/fun (

5、char a)if (*a)fun(a+1);/*found*/printf(%c *a);main()char s10=abcd;printf(处理前字符串=%sn处理后字符串=, s);fun(s); printf(n);解题答案:/*found*/void fun(char *a)/*found*/printf(%c, *a);*三、程序题:请编写一个函数fun,它的功能是:比较两个字符串的长度,(不得调用C语言 提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同, 则返回第一个字符串。 例如,输入beijing shanghai (为回车键), 函数将返回shang

6、hai。注意: 部分源程序存在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。给定源程序:#include char *fun (char *s, char *t)main()char a20,b20;void NONO ();printf(Input 1th string:);gets(a);printf(Input 2th string:);gets(b);printf(%sn,fun (a, b);NONO ();void NONO ()/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */FILE *f

7、p, *wf ;int i ;char a20, b20 ;fp = fopen(in.dat,r);wf = fopen(out.dat,w);for(i = 0 ; i next;if (p!=NULL)q=p-next;while(q!=NULL)if (p-data=q-data)p-next=q-next;/*found*/free(_1_);/*found*/q=p-_2_;elsep=q;/*found*/q=q-_3_;SLIST *creatlist(int *a)SLIST *h,*p,*q; int i;h=p=(SLIST *)malloc(sizeof(SLIST);

8、for(i=0; i q=(SLIST *)malloc(sizeof(SLIST);q-data=ai; p-next=q; p=q;p-next=0;return h;void outlist(SLIST *h)SLIST *p;p=h-next;if (p=NULL) printf(nThe list is NULL!n);elseprintf(nHead);do printf(-%d,p-data); p=p-next; while(p!=NULL);printf(-Endn);main()SLIST *head; int aN=1,2,2,3,4,4,4,5;head=creatli

9、st(a);printf(nThe list before deleting :n); outlist(head);fun(head);printf(nThe list after deleting :n); outlist(head);解题答案:/*found*/free(q);/*found*/q=p-next;/*found*/q=q-next;*二、改错题:给定程序MODI1.C中函数fun的功能是:用选择法对数组中的n个元素按从小到大的顺序进行排序。 请修改程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行和删行,也不得更改程序的结构!给定源程序:#includ

10、e #define N 20void fun(int a, int n)int i, j, t, p;for (j = 0 ;j n-1 ;j+) /*found*/p = jfor (i = j;i n; i+)if(ai ap)/*found*/p = j;t = ap ; ap = aj ; aj = t;main()int aN=9,6,8,3,-1,i, m = 5;printf(排序前的数据:);for(i = 0;i m;i+) printf(%d ,ai); printf(n);fun(a,m);printf(排序后的数据:);for(i = 0;i m;i+) printf(

11、%d ,ai); printf(n);解题答案:/*found*/p=j;/*found*/p=i;*三、程序题:请编写一个函数fun,它的功能是:求出1到m之间(含m)能被7或11整除的所有整数放在数组a中,通过n返回这些数的个数。例如,若传送给m的值为50,则程序输出: 7 11 14 21 22 28 33 35 42 44 49注意: 部分源程序存在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。给定源程序:#include #define M 100void fun (int m, int *a , int *n)ma

12、in()int aaM, n, k;void NONO ();fun (50, aa, &n);for (k = 0; k n; k+)if(k+1)%20=0) printf(n);else printf(%4d, aak);printf(n);NONO();void NONO ()/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */FILE *fp, *wf ;int i, n, j, k, aaM, sum ;fp = fopen(in.dat,r);wf = fopen(out.dat,w);for(i = 0 ; i 10 ; i+) fscanf(fp, %d,

13、 &j);fun(j, aa, &n);sum = 0 ;for(k = 0 ; k n ; k+) sum+=aak ;fprintf(wf, %dn, sum);fclose(fp);fclose(wf);参考答案:int i ;*n=0 ;for(i=7 ; inext;/*found*/while(p!=_1_)n+;/*found*/if (p-data=ch) return _2_;else p=p-next;return 0;main()SLIST *head; int k; char ch;char aN=m,p,g,a,w,x,r,d;head=creatlist(a);ou

14、tlist(head);printf(Enter a letter:);scanf(%c,&ch);/*found*/k=fun(_3_);if (k=0) printf(nNot found!n);else printf(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; i q=(SLIST *)malloc(sizeof(SLIST);q-data=ai; p-next=q; p=q;p-next=

15、0;return h;void outlist(SLIST *h)SLIST *p;p=h-next;if (p=NULL) printf(nThe list is NULL!n);elseprintf(nHead);doprintf(-%c,p-data); p=p-next;while(p!=NULL);printf(-Endn);解题答案:/*第一空*/while(p!=0)/*第二空*/if (p-data=ch) return n;/*第三空*/k=fun(head,ch);*二、改错题:给定程序MODI1.C中函数fun的功能是:删除p所指字符串中的所有空白字符(包括制表符、回车符

16、及换行符)。输入字符串时用#结束输入。 请改正程序中的错误,使它能输出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!给定源程序:#include #include #include fun (char *p)int i,t; char c80;/*found*/For (i = 0,t = 0; pi ; i+)if(!isspace(*(p+i) ct+=pi;/*found*/ct=0;strcpy(p,c);main()char c,s80;int i=0;printf(Input a string:);c=getchar();while(c!=#)si=

17、c;i+;c=getchar();si=0;fun(s);puts(s);解题答案:/*found*/for(i=0,t=0; pi; i+)/*found*/ct=0;*三、程序题:请编写一个函数fun,它的功能是:将ss所指字符串中所有下标为奇数位置上的字母转换为大写(若该位置上不是字母,则不转换)。 例如, 若输入abc4EFg,则应输出aBc4EFg。注意: 部分源程序存在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。给定源程序:#include #include void fun (char *ss)main()ch

18、ar tt81 ;void NONO ();printf(nPlease enter an string within 80 characters:n); gets(tt);printf(nnAfter changing, the stringn %s, tt);fun(tt);printf(nbecomesn %sn, tt);NONO ();void NONO ()/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */FILE *fp, *wf ;char tt81 ;int i ;fp = fopen(in.dat,r);wf = fopen(out.dat,w);for(i = 0 ; i 10 ; i+) fscanf(fp, %s, tt);fun(tt);fprintf(wf, %sn, tt);fclose(fp);fclose(wf);参考答案:int i ;for(i = 1 ; i = a & ssi next;while(p

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1