|
1997年4月全国计算机等级考试二级C语言试卷(含答案)(6) (10) 下面程序通过函数average计算数组中各元素的平均值,请填空. float average(int * pa,int n) { int i; float avg=0.0; for(i=0;iavg=【12】; return avg; } main() { int i,a[5]={2,4,6,8,10}; float mean; mean=average(a,5); printf("mean=%f\n",mean);} (11) 阅读程序: #include "string.h" #include "stdio.h" strle(char a[],char b[]) { int num=0,n=0; while(*(a+num)!='\0'),num++; while(b[n]){ *(a+num)=b[n];num++;n++;} return (num);} main() { char str1[81],str2[81],*p1=str1,*p2=str2; gets(p1); gets(p2); printf("%d\n",strle(p1,p2)); } 运行上面程序,如果从键盘上输入字符串qwerty和字符串abcd则程序的输出结果是 【13】 。 (12) 以下程序的输出结果是 【14】 。 fun(int n,int *s) { int f1,f2; if(n = =1n = =2) *s=1; else { fun(n-1,&f1); fun(n-2,&f2); *s=f1+f2;} } main() { int x; fun(6,&x); printf("%d\n",x); } (13) 阅读程序: main() { char str1[]="how do you do" ,str2[10]; char *p1=str1,*p2=str2; scanf("%s",p2); printf("%s",p2); printf("%s\n",p1); } 运行上面的程序,输入字符串HOW DO YOU DO 则程序的输出结果是【15】 。 (14) 以下程序由终端输入一个文件名,然后把从终端键盘输入的字符依次存放到该文件中,用#作为结束输入的标志.请填空. #include main() { FILE * fp; char ch,fname[10]; printf("lnput the name of file\n"); gets(fname); if((fp=【16】)==NULL) { printf("Cannot open\n"); exit(0);} printf("Enter data\n"); while((ch=getchar())!='#') fputc(【17】,fp); fclose(fp); } (15) 以下函数creat用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾。单向链表的头指针作为函数值返回.请填空: #include struct list { char data; struct list * next; }; struct list * creat() { struct list * h,* p,* q; char ch; h=【18】 malloc(sizeof(struct list)); p=q=h; ch=getchar(); while(ch!='?') { p=【19】 malloc(sizeof(struct list)); p->data=ch; p->next=p; q=p; ch=getchar(); } p->next='\0'; 【20】 } 1997年4月二级C笔试试卷参考答案 一 选择题((1)~(40)题每题1分,(41)~(50)题每题2分,共60分)
|