江苏省计算机二级C语言2005年春

2020-05-08 11:35

2005年春季笔试题及上机题

一、选择题 21.已知字符A的机内编码为65,则执行下列函数调用语句时,不能输出字符B的是 ____。 A. putchar('B'); B. putchar(\C. putchar(66); D. putchar('\\x42'); 22.下列一维数组的声明中正确的是_________。 A. int a[]; B. int n=10,a[n];

C. int a[10+1]={0}; D. int a[3]={1,2,3,4}; 23.已知有结构类型定义: typedef struct ex{long int num; char sex;

struct ex *next; }student; 下列叙述错误的是___________。

A. struct ex 是结构类型 B. student是结构类型的变量名 C. ex可缺省 D. student不可缺省 24.下列程序段的输出结果是___________。 int i,x[3][3]={9,8,7,6,5,4,3,2,1},*p=&x[1][1]; for(i=0;i<4;i+=2) printf(\

A. 5 2 B. 5 1 C. 5 3 D. 9 7

25.以下程序在编译时在第三行报错“Redeclaration of 'a' in function d”,如果决定修改该行声明中出现的局部变量a的名字,则下列选项中不能用来替换变量名a的是_________。 A. f B. e C. d D. b [程序] int b;

void d(int a)

{int f; double a=1; printf(\ } main()

{int e=1;d(e);}

26.已知有声明“char a[6],*p=a;”,现需要在程序运行过程中将字符串\保存到a数组中,则下列选项中能正确完成此操作的表达式是_________。 A. a[6]=\ B. a=\

C. p=\ D. strcpy(a,\

27.若要使表达式“P++”无语法错误,则变量P不能声明为___________。 A. int P; B. double P; C. int *P; D. struct{int x;}P; 28.以下语句中不包含关键字的是_____________。 A. x=sqrt(2); B. while(x!=0)x--; C. if(x<0)x=-x; D. return x;

29.以下函数定义中正确的是_____________。 A. int fun(inta,b){} B. int fun(int a[][]){}

C. int fun(void){} D. int fun(static int a,int b){}

30.已知有函数f的定义如下: int f(int a,int b)

{if(a

在main函数中若调用函数f(2,3),得到的返回值是________________。 A. 2 B. 3 C. 2和3 D. 3和2 二、填空题 ·基本概念题

1. 一个用C语言编写的程序在运行时,如果没有发生任何情况,则只有在执行了

_______函数的最后一条语句或该函数中的return语句后,程序才会终止运行。 2. 在C语言的源程序中若出现常量“1L”,则该常量的类型是____________。

3. 数学式

xy2?2a?b所对应的C语言表达式为_______________________________。

4. 已知有声明“int x=1,y=2;”,则执行表达式“(x>y)&&(--x>0)”后x的值为_________。 5. 在调用函数fopen(\时,若A:盘根目录下不存在文件b.dat,则函数的

返回值是_________。

·阅读程序题

6. 以下程序运行时输出结果为________________。 main()

{int x[4]={1,2,3,5},*p=x+2,i; for(i=0;i<2;i++) printf(\

7. 以下程序运行时输出结果为________________。 #include int func(int a) {static int c=1; c*=a; return c; } void main() {int b=1,i;

for(i=2;i<4;i++) b=b+func(i); printf(\

8. 以下程序输出结果为________________。 #include struct s {int a;

struct s *next; }; main() {int i;

static struct s x[2]={5,&x[1],7,&x[0]},*ptr; ptr=&x[0];

for(i=0;i<3;i++)

{printf(\

}

9. 以下程序输出结果为________________。 void f(int a,int *b) {a++;b++;(*b)++;} main()

{int i,x[2]={4,4}; f(x[0],&x[0]);

printf(\

10. 以下程序输出结果为________________。 #include #define ADD(x,y) x+y main()

{int a=15,b=10,c=20,d=5;

printf(\

11. 以下程序运行时输出结果的第一行为______________,第二行为____________。 #include #include

int process(char *s1,char *s2,char *s3)

{int i=0,j=0,len1=strlen(s1),len2=strlen(s2),len3=0; for(i=0;i=len2)

s3[len3++]=s1[i]; }

s3[len3]='\\0'; return len1-len3; }

void main()

{char s1[]=\ int n;

n=process(s1,s2,s3);puts(s3);printf(\

12. 以下程序运行时输出结果的第二行为______________,第四行为____________,第

六行为____________。 #include

void change(int s[3][3],int d) {int i,j,k; if(d= =0)

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

{k=s[i][j];s[i][j]=s[j][i];s[j][i]=k;} } else

for(i=0;i<3;i++)

for(j=0;j<3-i;j++)

{k=s[i][j];s[i][j]=s[2-j][2-i];s[2-j][2-i]=k;} }

main()

{int s[3][3]={1,2,3,4,5,6,7,8,9},i,j,k,n; change(s,0); for(i=0;i<3;i++)

{for(j=0;j<3;j++) printf(\ printf(\ }

change(s,1); for(i=0;i<3;i++)

{for(j=0;j<3;j++) printf(\ printf(\ } }

13. 以下程序运行时输出结果的第一行为______________,第二行为____________,第

三行为____________。 #include #include struct node {int d;

struct node *next; };

struct node *create(void)

{struct node *head=NULL,*p,*q=NULL; int i;

for(i=2;i<=9;i++)

{p=(struct node *)malloc(sizeof(struct node)); p->d=i; p->next=NULL; if(head= =NULL) head=p; else q->next=p; q=p; }

return head; }

void print(struct node *head) {if(head= =NULL) return; while(head->next!=NULL) {printf(\ head=head->next; }

printf(\}

struct node *delst(struct node *head,int *n) {int count=0; struct node *p,*q,*r; p=r=head;

while(p!=NULL) {q=p->next;

while(q!=NULL)

{if((q->d)%(p->d)= =0) {r->next=q->next; free(q);count++; q=r->next; } else

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

p=p->next; }

*n=count; return head; }

void main() {int y;

struct node *head; head=create(); print(head);

head=delst(head,&y); print(head);

printf(\·完善程序题

14. 已知方程x2-x-2=0在1.0附近有一个实根。以下程序中root为递归函数,采用牛顿

法计算方程x2-x-2=0在已知实数x附近的一个近似实根。算法提示:计算方程f(x)=0

在x0附近的一个近似实根的牛顿迭代公式为:

xi?1?xi?

f'(xi)f(xi)(i=0,1,2,??);

若|f(xi+1)|<ε,则认为xi+1是方程f(x)=0在允许误差ε范围内的一个实根。以下程序计算时ε取值为0.000001。 #include #include double f(double x) {return x*x-x-2; }

double f1(double x) /*计算f '(x)的值*/ {return 2*x-1; }

double root(double x) {double y;


江苏省计算机二级C语言2005年春.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:优秀示范管理小区迎检资料总目录

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: