77范文网 - 专业文章范例文档资料分享平台

2009 - 秋二级C语言考题及答案(2)

来源:网络收集 时间:2019-04-15 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

2009年10月17日江苏省高校C语言二级考试书面试卷

else return x[0]+fun(x+1,n-1); }

void main()

{ int a[]={1,2,3,4,5,6};

printf(\}

(答案为(10)6 )

10. 以下程序运行时输出结果中第一行是_____(11)____。

#include long f(int n) { static long s;

if(n==1) return s=2; else return ++s; }

void main()

{ long i,sum=0;

for(i=1; i<4; i++) sum+=f(i); printf(\} (答案:(11) 9 P189验证第八章static语句功能:初始值为0;以后调用时保持上次调用值 )

11.以下程序运行时输出到屏幕的结果中第一行是____(12)_____,第二行是_____(13)____。

#include #define f(x,y) y=x*x void g(int x, int y) { y=x*x; } void main()

{ int a=2,b=0,c=2,d=0; f(a,b); g(c,d);

printf(\}

(答案:第一行(12) 4 第二行为(13))0)

12. 以下程序运行时输出到屏幕的结果中第一行是____(14)_____,第三行是_____(15)____。

#include void main()

{ int a[3][3]={{3,8,12},{4,7,10},{2,5,11}},i,j,k,t; for(j=0;j<3;j++)

for(k=0;k<2;k++) for(i=0;i<2;i++) if(a[i][j]>a[i+1][j])

t=a[i][j],a[i][j]=a[i+1][j],a[i+1][j]=t; for(i=0;i<3;i++)

第 6 页 共 11 页

2009年10月17日江苏省高校C语言二级考试书面试卷

{ for(j=0;j<3;j++)

printf(\ printf(\ } }

(答案:第一行是(14) 2 5 10 第三行是(15) 4 8 12 ) 13. 以下程序运行时输出到屏幕的结果是__(16)__。

#include #include void main()

{ int i=0,n=0; char s[80], *p; strcpy(s, \ for(p=s; *p!= '\\0'; p++) if(*p==' ') i=0; else

if(i==0)

{ n++; i=1;} printf(\}

(答案: (16)是 4)

14. 以下程序运行时输出到屏幕的结果中第一行是__(17)__,第二行是__(18)__。

#include typedef struct fact { int m,z; } FACT;

FACT fun1(FACT t1, FACT t2) { FACT t3;

t3.m=t1.m*t2.m;

t3.z=t1.z*t2.m+t2.z*t1.m; return t3; }

FACT fun2(FACT t) { int m,n,k; m=t.m; n=t.z;

while(k=m%n) { m=n; n=k; } t.m=t.m/n; t.z=t.z/n; return t; }

void main()

第 7 页 共 11 页

2009年10月17日江苏省高校C语言二级考试书面试卷

{ FACT s,s1={8,4}, s2={6,5}; s=fun1(s1,s2);

printf(\ s=fun2(s);

printf(\}

(答案:(17):64,48 (18):4, 3)

? 完善程序

15. 以下程序求方程的一个近似根。Root函数采用二分法计算并返回方程f(x)=0在[a,b]内的一个近似根,main函数调用root函数求方程cos(x)=0在[0,3.14]内的一个近似根。试完善程序以达到要求的功能。

#include #include

double root(double a, double b, double (*f)(double)) /*书P260用函数指针变量调用库函数cos*/

{ double x,y;

if(__(19)__) /*区间起终值同号为无根*/ { printf(\ return 0; }

do

{ x=__(20)__;

y=f(x); /*区间中点函数值*/ if(fabs(y)<1e-6||fabs(b-a)<1e-6) break; /*函数根值时跳出*/

if(__(21)__<0) b=x; /*区间起始值与中间点异号*/ else a=x; /*区间起始值与中间点同号*/ }while(1); return x; } void main()

{ printf(\__(22)__)); } /*指针变量f指向库函数cos*/ (答案:(19):f(a)*f(b)>0 (20):(a+b)/2 (21):f(a)*y (22):cos 16. 以下程序在3~50范围内验证:大于等于3的两个相邻素数的平方之间至少有4个素数。例如3和5是相邻素数,32~52之间有素数11、13、17、19、23。试完善程序以达到要求的功能。

#include #include #include int prime(int n) { int i;

for(i=2;i<=sqrt(n);i++) if(__(23)__) return 0; return 1;

第 8 页 共 11 页

2009年10月17日江苏省高校C语言二级考试书面试卷

}

void main()

{ int i,j,k=0,m,n,c,a[30]={0}; for(i=3;i<50;i++)

if(prime(i)) __(24)__; /*将3-49区间素数存入a数组,素数个数存入

变量k*/

for(i=0;i

for(j=m+1;j=4)

printf(\ %d*%d-%d*%d: %d\ else { printf(\ } }

(答案:(23):n%i==0 (24):a[k++]=i (25):0 (26):prime(j)

17. fun函数的功能是删除s指向的链表中满足以下条件的结点:该结点的编号值是奇数且存放的字母ASCII编码值也为奇数(提示:a的ASCII编码是97);将删除的结点添加到t指向的链表尾部。试完美fun函数以达到要求的功能。 例如:若删除前排s链表为: s→①…→②…→③…→④ 则删除后的s链表为: s→②…→③…→④

#include struct node { int i; char c;

struct node *next; };

struct node *t=NULL;

struct node *fun(struct node *s)

{ struct node *p, *q; struct node *r; p=q=s;

while(p!=NULL)

{ if(((p->i)%2)&&((p->c)%2)) { if(s==p)

s=q=__(27)__;

else

{ __(28)__; q=p->next;

}

第 9 页 共 11 页

2009年10月17日江苏省高校C语言二级考试书面试卷

if(t==NULL) t=r=p; else

{ r->next=p; r=r->next;}

}

p=__(29)__;

}

if(t!=NULL) __(30)__; return s; }

答案:(27):p->next (28):t->next=p (29):p->next 调试程序 #include struct node { int i; char c;

struct node *next; };

struct node *t=NULL;

struct node *fun(struct node *s)

{ struct node *p, *q; struct node *r; p=q=s;

while(p!=NULL)

{ if(((p->i)%2)&&((p->c)%2)) { if(s==p)

s=q=p->next; else

{ t->next=p; q=p->next;} if(t==NULL) t=r=p; else { r->next=p; r=r->next;} } p=p->next; }

if(t!=NULL)

t->next=NULL; return s; }

void print(struct node *phead) { while(phead)

{ printf(\ \

(30):t->next=NULL

第 10 页 共 11 页

2009年10月17日江苏省高校C语言二级考试书面试卷

phead=phead->next; }

printf(\}

void main()

{ struct node a[4], *head=a; int j; for(j=0;j<4;j++) { a[j].i=j+1; if(j>1) a[j].c='a'+j-1; else a[j].c='a'+j; a[j].next=&a[j+1]; }

a[j-1].next=NULL; /*生成链表*/ print(head);

head=fun(head); print(head); head=t; print(head); }

原始链表 删除后链表

被删除部份链表 第 11 页 共 11 页

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库2009 - 秋二级C语言考题及答案(2)在线全文阅读。

2009 - 秋二级C语言考题及答案(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/599390.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: