计算机二级C语言上机试题100套及答案.doc
文本预览下载声明
上 机 题 库第一部分 ?填空题?????????????????????????????????????????????????????????????
注意:源程序存放在考生文件夹下的BLANK1.C中。1. 不得增行或删行,也不得更改程序的结构!2. 请在程序下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。?????????????????????????????????????????????????????????????
1. 给定程序中,函数FUN的功能是:计算出带有头接点的单向链表中各结点数据域之和作为函数值返回。#include ?stdio.h
#include ?stdlib.h
#define ???N ???8
typedef ?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-___1___; ????????????????????????????data
/**********************************found*********************************/
???p=p-___2___; ?????????????????????????????next
??}
??return s;
}
main( )
{ ?SLIST ?*head;
??int ?a[N]={12,87,45,32,91,16,20,48};
??head=creatlist(a); ???outlist(head);
/**********************************found*********************************/
??printf(\nsum=%d\n, fun(___3___)); ????????????????head
}
SLIST *creatlist(int ?a[ ])
{ ?SLIST ?*h,*p,*q; ?????int ?i;
??h=p=(SLIST *)malloc(sizeof(SLIST));
??for(i=0; iN; i++)
??{ ?q=(SLIST *)malloc(sizeof(SLIST));
???q-data=a[i]; ?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
??{ ?printf(\nHead ?);
???do
???{ ?printf(-%d, p-data); p=p-next; ?}
???while(p!=NULL);
???printf(-End\n);
?}
}
2. 给定程序中,函数FUN的功能是:求出形参SS所指字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中工有M个字符串,且串长N。#include ??stdio.h
#include ??string.h
#define ???M ???5
#define ???N ???20
void fun(char ?(*ss)[N])
{ ?int ?i, j, k=0, n, m, len;
??for(i=0; iM; i++)
??{ ?len=strlen(ss[i]);
???if(i==0) n=len;
???if(lenn) {
/**********************************found*********************************/
????n=len; ???k=___1___; ????????????????????????????i
???}
??}
??for(i=0; iM; i++)
???if (i!=k)
???{ m=n;
???len=strlen(ss[i]);
/*********************************
显示全部