[IT认证]计算机2级C语言上机考题.doc
《[IT认证]计算机2级C语言上机考题.doc》由会员分享,可在线阅读,更多相关《[IT认证]计算机2级C语言上机考题.doc(210页珍藏版)》请在三一文库上搜索。
1、第4套上机考试试题 一、程序填空题 给定程序的功能是:调用函数fun将指定源文件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,败时返回值为0。在复制的过程中,把复制的内容输出到 终端屏幕。主函数中源文件名放在变量sfname中,目标文 件名放在变量tfname中。请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1C中。 不得增行或删行,也不得更改程序的结构! #include #include int fun(char *source, char *target)FILE *fs,*ft; char ch;/*fo
2、und*/ 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_) putchar(ch);/*found*/ fputc(ch,_3_); ch=fgetc(fs); fclose(fs); fclose(ft); printf(nn); return 1;main()char sfname20 =myfile1,tfname20=myfile2; F
3、ILE *myf; int i; char c; myf=fopen(sfname,w); printf(nThe original data :n); for(i=1; i30; i+)c=A+rand()%25;fprintf(myf, %c,c); printf(%c,c); fclose(myf);printf(nn); if (fun(sfname, tfname) ) printf(Succeed!); else printf(Fail!);二、程序修改题 给定程序MODI1C中函数fun的功能是:将长整型数 s中每一位上为偶数的数依次取出,构成一个新数放在t中。 高位仍在高位,低
4、位仍在低位。 例如,当s中的数为:87653142时,t中的数为:8642。 请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得 更改程序的结构! #include void fun (long s, long *t)int d; long sl=1; *t = 0; while (s 0) d = s%10;/*found*/ if (d%2=0) *t=d* sl+ *t; sl *= 10; /*found*/ s = 10; main()long s, t; printf(nPlease enter s:); scanf(%ld, &s); f
5、un(s, &t); printf(The result is: %ldn, t);三、程序设计颢 函数fun的功能是:将两个两位数的正整数a,b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的十位和千位上,b数的十位和个位数依次放在c数的百位和个位上。 例如,当a=45,b=12时,调用该函数后,c=5142。 注意:部分源程序存在文件PROGl.C中,数据文件 in.dat中的数据不得修改。 请勿改动主函数main和其他函数中的任何内容,仅在 函数fun的花括号中填入你编写的若干语句。 #include void fun(int a, int b, long *c
6、)main()int a,b; long c; void NONO (); printf(Input a, b:); scanf(%d,%d, &a, &b); fun(a, b, &c); printf(The result is: %ldn, c); NONO();void NONO ()/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen(in.dat, r); wf = fopen(out.dat,w); for(i = 0 ; i 10 ; i+) fscanf(rf
7、, %d,%d, &a, &b); fun(a, b, &c); fprintf(wf, a=%d,b=%d,c=%ldn, a, b, c); fclose(rf); fclose(wf);第5套上机考试试题 一、程序填空题 给定程序中已建立一个带有头结点的单向链表,链表中 的各结点按结点数据域中的数据递增有序链接,姜。函数fun的 功能是:把形参x的值放入一个新结点并插入到链表中,插 后各结点数据域的值仍保持递增有序。请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANKl.C中。 不得增行或删行,也不得更改程序的结构! #inc
8、lude #include #define N 8typedef struct listint data; struct list *next; SLIST;void fun(SLIST *h, int x)SLIST *p, *q, *s; s=(SLIST *)malloc(sizeof(SLIST);/*found*/ s-data=_1_; q=h; p=h-next; while(p!=NULL & xp-data) /*found*/ q=_2_; p=p-next; s-next=p;/*found*/ q-next=_3_;SLIST *creatlist(int *a)SLI
9、ST *h,*p,*q; int i; h=p=(SLIST *)malloc(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(nThe list is NULL!n); else printf(nHead); do printf(-%d,p-data); p=p-next; while(p!=NULL); printf(-Endn); main()SLIST *head; int x;
10、 int aN=11,12,15,18,19,22,25,29; head=creatlist(a); printf(nThe list before inserting:n); outlist(head); printf(nEnter a number : ); scanf(%d,&x); fun(head,x); printf(nThe list after inserting:n); outlist(head);二、程序修改题 给定程序MODIl.C中函数fun的功能是:计算正整数 num的各位上的数字之积。 例如,若输入:252,则输出应该是:20。若输入:202, 则输出应该是:0。
11、请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得 更改程序的结构! #include long fun (long num)/*found*/ long k; do k*=num%10 ;/*found*/ num=10 ; while(num); return (k);main()long n ; printf(nPlease enter a number:); scanf(%ld,&n); printf(n%ldn,fun(n);三、程序设计题 请编写一个函数fun,它的功能是:计算n门课程的平 均分,计算结果作为函数值返回。 例如:若有5门课
12、程的成绩是:90.5,72,80,61.5,55 则函数的值为:71.80。注意:部分源程序存在文件PROG1C中。 请勿改动主函数main和其他函数中的任何内容,仅在 函数fun的花括号中填入你编写的若干语句。 #include float fun (float *a , int n)main()float score30=90.5, 72, 80, 61.5, 55, aver; void NONO (); aver = fun(score, 5); printf(nAverage score is: %5.2fn, aver); NONO ();void NONO ()/* 本函数用于打
13、开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; int i, j ; float aver, score5 ; fp = fopen(in.dat,r); wf = fopen(out.dat,w); for(i = 0 ; i 10 ; i+) for(j = 0 ; j 5 ; j+) fscanf(fp,%f,&scorej); aver = fun(score, 5); fprintf(wf, %5.2fn, aver); fclose(fp); fclose(wf);第6套上机考试试题 一、程序填空题 给定程序中已建立一个带有头结点的单向链表,
14、在 main函数中将多次调用fun函数,每调用一次fun函数,输 出链表尾部结点中的数据,并释放该结点,使链表缩短。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANKIC中。 不得增行或删行,也不得更改程序的结构! #include #include #define N 8typedef struct listint data; struct list *next; SLIST;void fun(SLIST *p)SLIST *t, *s; t=p-next; s=p; while(t-next != NULL) s=t;/*f
15、ound*/ 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; 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(nThe list is NULL!n); else p
16、rintf(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 != NULL) fun(head); printf(nn); printf(nOutput from head agai
17、n :n); outlist(head); 二、程序修改题 给定程序MODII.C中函数fun的功能是:将字符串中 的字符按逆序输出,但不改变字符串中的内容。例如,若字符串为abcd,则应输出:dcba。 请改正程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得 更改程序的结构! #include /*found*/fun (char a)if (*a) fun(a+1);/*found*/ printf(%c *a); main()char s10=abcd; printf(处理前字符串=%sn处理后字符串=, s); fun(s); printf(n
18、);三、程序设计题 请编写一个函数fun,它的功能是:比较两个字符串的 长度,(不得调用C语言提供的求字符串长度的函数),函 数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。例如,输入beijing shanghai(为回车键),函数将返回shanghai。注意:部分源程序存在文件PROGl.C中。请勿改动主函数main租其他函数中的任何内容,仅在 函数fun的花括号中填入你编写的若干语句。 #include char *fun (char *s, char *t)main()char a20,b20; void NONO (); printf(Input 1th string:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- IT认证 IT 认证 计算机 语言 上机 考题
链接地址:https://www.31doc.com/p-1964809.html