您现在的位置:学赛首页 > 计算机等级考试 > 模拟试题 > 正文
计算机等级考试二级C语言模拟试题十及答案解析[8]
http://www.educity.cn 作者:希赛等考学院 来源:希赛网 2007年9月20日 发表评论 进入社区
更多二级C语言学习资料:http://www.educity.cn/ncre/zt/ZT_C_cc0911.htm

(13)下面程序的功能是:对字符串从小到大进行排序并输出,请填空。
#include "string.h"
#include "stdio.h"
sort(char *a[],int n)
{ int i,j;
char *p;
for(j=1;j<=n-1;j++)
for(i=0; 【15】 ;i++)
if( 【16】 >0)
{ p=a[i];
a[i]=a[i+1];
a[i+1]=p;}}
main()
{ int i;
char *book[]={"itisme","itisyou","howareyou","fine","goodnight","goodbye"};
sort( 【17】 );
for(i=0;i<6;i++)
printf("%s\n",book[i]);}
正确答案:  1.(i<n-j) 2.(strcmp(a[i],a[i+1])) 3.(book,6)

(14)下面的函数是完成1~n的累加,完成函数。
a(int k)
{if(k<=0)printf("error\n");
if(k==1) 【18】 ;
else 【19】 ;}
正确答案:  1.(return 1) 2.(return(a(k-1)+k))

(15)阅读下列程序,则程序实现的功能是 【20】 。
#include "stdio.h"
struct node
{ char data;
 struct node *next; } *head;
fun(struct node *q)
{ if(head == NULL)
{q->next=NULL;
head=q;}
else
{ q->next=head;
head=q;}}
main()
{char ch;
struct node *p;
head = NULL;
while((ch=getchar())!=′\n′)
{p=(struct node *)malloc(sizeof(struct node));
p->data=ch;
fun(p); }
p=head;
while(p!=NULL)
{printf("%c",p->data);
p=p->next; }}
正确答案:  1.(从键盘输入一行字符串,调用函数建立反序的链表,然后输出整个链表)

 

[1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]