2014年上半年计算机等级二级C语言上机精选模拟试题7

牛课网考试宝典 更新时间:13-12-28

为了帮助大家复习好计算机等级考试,本次我们考吧网特为广大考生整理了计算机等级考试模拟试题,希望广大考生能够喜欢。本次主要汇编了2014年上半年计算机等级二级C语言上机精选模拟试题:

编辑推荐:2014年上半年计算机等级二级C语言上机精选模拟试题汇总十 

给定程序中,函数fun的功能是:在带有头结点的单向链表中,查找数据域中值为ch的结点。找到后通过函数值返回该结点在链表中所处的顺序号;若不存在 值为ch的结点,函数返回0值。

请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

注意:源程序存放在考生文件夹下的BLANK1.C中。

不得增行或删行,也不得更改程序的结构!

给定源程序:

#include

#include

#define N 8

typedef struct list

{ int data;

struct list *next;

} SLIST;

SLIST *creatlist(char *);

void outlist(SLIST *);

int fun( SLIST *h, char ch)

{ SLIST *p; int n=0;

p=h->next;

while(p!=___1___)

{ n++;

if (p->data==ch) return ___2___;

else p=p->next;

}

return 0;

}

main()

{ SLIST *head; int k; char ch;

char a[N]={’m’,’p’,’g’,’a’,’w’,’x’,’r’,’d’};

head=creatlist(a);

outlist(head);

printf("Enter a letter:");

scanf("%c",&ch);

k=fun(___3___);

if (k==0) printf("Not found!");

else printf("The sequence number is : %d",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=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!");

else

{ printf("Head");

do

{ printf("->%c",p->data); p=p->next; }

while(p!=NULL);

printf("->End");

}

}

解题思路:

本题是在给定的链表中要求找出指定的值。

第一处:判断p是否结束,所以应填:NULL。

第二处:在函数fun中,使用n来计算结点的位置,当找到ch值,则返回结点的位置n,所以应填:return n。

第三处:函数调用,在主函数中已经给出了head和ch,所以应填:head,ch。

下一篇:2014年上半年计算机等级二级C语言上机精选模拟试题8

考试宝典安装说明

宝典适用于手机、电脑、平板,您可安装客户端或在浏览器使用。

电脑版

手机版

网页版

考试宝典咨询
服务热线

TEL:029-88699698