您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页二级C语言模拟题2018年(24)_真题-无答案

二级C语言模拟题2018年(24)_真题-无答案

来源:华佗小知识


二级C语言模拟题2018年(24) (总分100,考试时间90分钟)

一、程序填空题

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

请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。

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

#include<stdio.h> #include<stdlib.h> #define N 8

typedef struct list {int data;

struct list *next; }SLIST;

SLIST *creatlist(char*); void outlisf(SLIST*); int fun(SLIST *h, char ch) {SLIST *p; int n=0; p=h->next;

/**********found**********/ while(p!=______) (n++;

/**********found**********/ if(p->data==ch)return______; else p=p->next; }

return 0; }

main ()

(SLIST *head; int k; char ch;

char a[N]={\"m\ head=creatlist(a); outlist(head);

printf(\"Enter a letter:\"); scanf(\"%c\

/**********found**********/ k=fun(______); if(k==0)

printf(\"\\nNot found!\\n\"); else

printf(\"The sequence number is:%d\\n\ SLIST *creatlist(char *a) (SLIST *h, *p, *q; int i;

h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i<N; 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(\"\\nThe list is NULL!\\n\"); else

{printf(\"\\nHead\"); do

{printf(\"->%c\

p->data); p=p->next;} while(p!=NULL); printf(\"->End\\n\"); } }

二、程序改错题

1. 下列给定程序中,函数fun的功能是:删除指针p所指字符串中的所有空白字符(包括制表符、回车符及换行符)。

输入字符串时用“#”结束输入。

请改正程序中的错误,使它能输出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序:

#include<string.h> #include<stdio.h>

#include<ctype.h> fun(char *p) {

int i, t; char c[80];

/**********found**********/ for(i=0, t=0; p[i]; i++) if(!isspace(*{p+i))) c[t++]=p[i];

/**********found**********/ c[t]=\"\\0\"; strcpy(p, c); }

void main() {

char c, s[80]; int i=0;;

printf(\"Input a string:\"); c=getchar(); while(c!=\"#\")

{s[i]=c; i++; c=getchar();} s[i]=\"\\0\"; fun(s); puts(s); }

三、程序设计题

1. 编写函数fun,其功能是:将ss所指字符串中所有奇数位上的字母转换为大写(若该位置上不是字母,则不转换)。

例如,若输入“abc4EFg”,则应输出“aBc4EFg”。 注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任伺内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:

#include<conio.h> #include<stdio.h> #include<string.h> void fun(char*ss) { }

void main(void) {

char tt[51];

printf(\"\\nPlease enter an character string within 50 characters:\\n\");

gets(tt);

printf(\"\\n\\nAfter changing,the string\\n%s\ fun(tt);

printf(\"\\nbecomes\\n %s\ }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务