广科c语言考试题及答案_第1页
广科c语言考试题及答案_第2页
广科c语言考试题及答案_第3页
广科c语言考试题及答案_第4页
广科c语言考试题及答案_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

广科c语言考试题及答案一、选择题(8题,每题3分,共24分)

1.下列哪个选项不是C语言的关键字?

A.int

B.float

C.string

D.char

2.在C语言中,如何定义一个常量?

A.varconst=5;

B.#defineCONSTANT5

C.constintCONSTANT=5;

D.alloftheabove

3.以下哪个选项是正确的C语言注释?

A./*Thisisacomment*/

B.//Thisisacomment

C.BothAandB

D.NeitherAnorB

4.以下哪个选项表示正确的C语言变量命名规则?

A.1variable

B._variable

C.variable_1

D.Alloftheabove

5.在C语言中,哪个运算符用于取模?

A.*

B./

C.%

D.+

6.以下哪个选项是正确的C语言条件语句?

A.if(x==y)thenx=y;

B.ifx==yx=y;

C.if(x==y){x=y;}

D.ifx=yx=y;

7.在C语言中,以下哪个选项是正确的循环语句?

A.while(x<y)x++;

B.for(x=0;x<y;x--)x++;

C.repeatx++;until(x<y);

D.Alloftheabove

8.以下哪个选项是正确的C语言数组定义?

A.intarr[5];

B.intarr(5);

C.intarr={1,2,3,4,5};

D.Alloftheabove

二、(一)多项选择题(5题,每题4分,共20分)

1.下列哪些是C语言的基本数据类型?

A.int

B.float

C.char

D.string

E.double

2.以下哪些是C语言的控制结构?

A.if-else

B.switch

C.for

D.while

E.do-while

3.以下哪些语句在C语言中是合法的?

A.intx=5;

B.x=y+z;

C.y=x*z;

D.x=y/z;

E.x=y%z;

4.以下哪些是C语言的运算符?

A.+,-,*,/

B.==,!=,>,<

C.&&,||,!

D.=,+=,-=

E.Alloftheabove

5.以下哪些是C语言的函数定义?

A.voidfunction(){/*code*/}

B.intfunction(intx,inty){returnx+y;}

C.floatfunction(floatx){returnx*2;}

D.function(){/*code*/}

E.voidfunction(intx){/*code*/}

(二)判断题(7题,每题2分,共14分)

1.C语言中的变量必须在使用前声明。

2.C语言中的字符串是用双引号表示的。

3.C语言中的数组索引是从1开始的。

4.C语言中的switch语句可以处理字符串。

5.C语言中的while循环至少执行一次。

6.C语言中的do-while循环至少执行一次。

7.C语言中的常量在编译时被确定。

三、(一)填空题(10题,每题2分,共20分)

1.在C语言中,用于输出信息的函数是________。

2.在C语言中,用于输入信息的函数是________。

3.在C语言中,用于定义函数的关键字是________。

4.在C语言中,用于表示逻辑非的运算符是________。

5.在C语言中,用于表示逻辑或的运算符是________。

6.在C语言中,用于表示逻辑与的运算符是________。

7.在C语言中,用于定义数组的方括号是________。

8.在C语言中,用于表示条件语句的关键字是________。

9.在C语言中,用于表示循环语句的关键字是________。

10.在C语言中,用于定义常量的关键字是________。

(二)计算题(3题,每题6分,共18分)

1.写一个C语言程序,计算两个数的和并输出结果。

2.写一个C语言程序,判断一个数是否为偶数并输出结果。

3.写一个C语言程序,计算1到10的累加和并输出结果。

四、综合题(2题,每题10分,共20分)

1.编写一个C语言程序,实现一个简单的计算器,可以加、减、乘、除四个功能。

2.编写一个C语言程序,实现一个简单的学生成绩管理系统,可以添加、删除、修改和查询学生的成绩。

五、材料分析题(2题,每题14分,共28分)

1.分析以下C语言代码的功能,并解释其中的关键语句。

```c

#include<stdio.h>

intmain(){

intx=5,y=10;

if(x<y){

printf("xislessthany\n");

}else{

printf("xisnotlessthany\n");

}

return0;

}

```

2.分析以下C语言代码的功能,并解释其中的关键语句。

```c

#include<stdio.h>

intmain(){

intarr[5]={1,2,3,4,5};

inti;

for(i=0;i<5;i++){

printf("%d",arr[i]);

}

printf("\n");

return0;

}

```

答案部分:

一、选择题

1.C

2.D

3.C

4.B

5.C

6.C

7.A

8.A

二、(一)多项选择题

1.A,B,C,E

2.A,B,C,D,E

3.A,B,C,D,E

4.E

5.A,B,C,E

(二)判断题

1.正确

2.正确

3.错误

4.错误

5.正确

6.正确

7.正确

三、(一)填空题

1.printf

2.scanf

3.void

4.!

5.||

6.&&

7.[]

8.if

9.while,for,do-while

10.const

(二)计算题

1.

#include<stdio.h>

intmain(){

intx,y,sum;

printf("Entertwonumbers:");

scanf("%d%d",&x,&y);

sum=x+y;

printf("Sum=%d\n",sum);

return0;

}

2.

#include<stdio.h>

intmain(){

intx;

printf("Enteranumber:");

scanf("%d",&x);

if(x%2==0){

printf("Thenumberiseven\n");

}else{

printf("Thenumberisodd\n");

}

return0;

}

3.

#include<stdio.h>

intmain(){

inti,sum=0;

for(i=1;i<=10;i++){

sum+=i;

}

printf("Sum=%d\n",sum);

return0;

}

四、综合题

1.

#include<stdio.h>

voidadd(intx,inty){

printf("Sum=%d\n",x+y);

}

voidsubtract(intx,inty){

printf("Difference=%d\n",x-y);

}

voidmultiply(intx,inty){

printf("Product=%d\n",x*y);

}

voiddivide(intx,inty){

if(y!=0){

printf("Quotient=%d\n",x/y);

}else{

printf("Divisionbyzeroisnotallowed\n");

}

}

intmain(){

intx,y;

charop;

printf("Enteranoperation(+,-,*,/):");

scanf("%c",&op);

printf("Entertwonumbers:");

scanf("%d%d",&x,&y);

switch(op){

case'+':

add(x,y);

break;

case'-':

subtract(x,y);

break;

case'*':

multiply(x,y);

break;

case'/':

divide(x,y);

break;

default:

printf("Invalidoperation\n");

}

return0;

}

2.

#include<stdio.h>

#defineMAX_STUDENTS100

typedefstruct{

intid;

charname[50];

floatgrade;

}Student;

Studentstudents[MAX_STUDENTS];

intstudent_count=0;

voidadd_student(intid,char*name,floatgrade){

if(student_count<MAX_STUDENTS){

students[student_count].id=id;

strcpy(students[student_count].name,name);

students[student_count].grade=grade;

student_count++;

}else{

printf("Maximumnumberofstudentsreached\n");

}

}

voiddelete_student(intid){

inti,found=0;

for(i=0;i<student_count;i++){

if(students[i].id==id){

found=1;

break;

}

}

if(found){

for(;i<student_count-1;i++){

students[i]=students[i+1];

}

student_count--;

printf("StudentwithID%ddeleted\n",id);

}else{

printf("StudentwithID%dnotfound\n",id);

}

}

voidmodify_student(intid,char*name,floatgrade){

inti,found=0;

for(i=0;i<student_count;i++){

if(students[i].id==id){

found=1;

break;

}

}

if(found){

strcpy(students[i].name,name);

students[i].grade=grade;

printf("StudentwithID%dmodified\n",id);

}else{

printf("StudentwithID%dnotfound\n",id);

}

}

voidquery_student(intid){

inti,found=0;

for(i=0;i<student_count;i++){

if(students[i].id==id){

found=1;

break;

}

}

if(found){

printf("ID:%d,Name:%s,Grade:%.2f\n",students[i].id,students[i].name,students[i].grade);

}else{

printf("StudentwithID%dnotfound\n",id);

}

}

intmain(){

add_student(1,"JohnDoe",85.5);

add_student(2,"JaneSmith",92.0);

query_student(1);

modify_student(1,"JohnDoeJr.",87.0);

delete_student(2);

return0;

}

五、材料分析题

1.该代码的功能是判断两个数x和y的大小关系,并输出结果。关键语句包括:

-`intx=5,y=10;`:定义并初始化两个整数变量x和y。

-`if(x<y)`:判断x是否小于y。

-`printf("xislessthany\n");`:如果x小于y,输出"x

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论