TSheet1副本.docx

上传人:b****8 文档编号:8985766 上传时间:2023-02-02 格式:DOCX 页数:16 大小:17.93KB
下载 相关 举报
TSheet1副本.docx_第1页
第1页 / 共16页
TSheet1副本.docx_第2页
第2页 / 共16页
TSheet1副本.docx_第3页
第3页 / 共16页
TSheet1副本.docx_第4页
第4页 / 共16页
TSheet1副本.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

TSheet1副本.docx

《TSheet1副本.docx》由会员分享,可在线阅读,更多相关《TSheet1副本.docx(16页珍藏版)》请在冰豆网上搜索。

TSheet1副本.docx

TSheet1副本

试卷号:

TSheet1

一、选择题

1、C语言源程序文件的后缀名一般为.c,源代码经编译后生成的目标文件,其后缀名为______。

(A).txt

(B).c

(C).obj

(D).exe

答案:

C

2、以下选项中,合法的用户标识符是_______。

(A)_2Test

(B)3max

(C)long

(D)A.dat

答案:

A

3、若有以下定义:

chara;intb;

floatc;doubled;

则表达式a*b+d-c值的类型为______。

(A)float

(B)int

(C)char

(D)double

答案:

D

4、设a=1,b=2,c=3,d=4,则表达式:

a

a:

c

a:

d的结果为______。

(A)4

(B)3

(C)2

(D)1

答案:

D

5、设x,y,z,t均为int型变量,则执行以下语句后,t的值为_____。

x=y=z=0;

t=++x||++y&&++z;

(A)不定值

(B)2

(C)1

(D)0

答案:

C

6、设x和y均为int型变量,则执行以下的循环后,y值为______。

for(y=1,x=1;y<=50;y++)

{

if(x==10)break;

if(x%2==1)

{

x+=5;

continue;

}

x-=3;

}

(A)2

(B)4

(C)6

(D)8

答案:

C

7、以下叙述中不正确的是_____。

(A)在不同的函数中可以使用相同名字的变量

(B)函数中的形式参数是局部变量

(C)在一个函数内定义的变量只在本函数范围内有效

(D)在一个函数内的复合语句中定义的变量在本函数范围内有效

答案:

D

8、假定a和b为int型变量,则执行以下语句后b的值为______。

a=1;b=10;

do

{b-=a;a++;}while(b--<0);

(A)9

(B)8

(C)-1

(D)-2

答案:

B

9、若定义:

inta=511,*b=&a;,则printf("%d\n",*b);的输出结果为_____。

(A)511

(B)a的地址

(C)512

(D)无确定值

答案:

A

10、以下程序段的输出结果是______。

inta=0,i;

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

{

switch(i){

case0:

case3:

a+=2;

case1:

case2:

a+=3;

default:

a+=5;

}

}

printf("%d\n",a);

(A)41

(B)13

(C)10

(D)20

答案:

A

11、设p1和p2是指向同一个int型一维数组的指针变量,k为int型变量,则不能正确执行的语句是______。

(A)k=*p1+*p2;

(B)p2=k;

(C)p1=p2;

(D)k=*p1*(*p2);

答案:

B

12、在C语言中,形参的缺省存储类型是______。

(A)auto

(B)register

(C)static

(D)extern

答案:

A

13、若已定义inta[3][4],(*p)[4];下列赋值表达式中______是正确的。

(A)p=*a

(B)p=a[1]

(C)p=*a+2

(D)p=a+2

答案:

D

14、设有以下说明语句

typedefstruct

{intn;

charch[8];

}PER;

则下面叙述中正确的是_____。

(A)PER是结构体变量名

(B)PER是结构体类型名

(C)typedefstruct是结构体类型

(D)struct是结构体类型名

答案:

B

15、按读写方式打开D:

\jsj\A.txt的正确格式是______。

(A)FILE*fp;fp=fopen("D:

\jsj\A.txt","r");

(B)FILE*fp;fp=fopen("D:

\\jsj\\A.txt","r+");

(C)FILE*fp;fp=fopen("D:

\\jsj\\A.txt","rb+");

(D)FILE*fp;fp=fopen("D:

\\jsj\\A.txt","w");

答案:

B

二、填空题

1、一个C程序中至少应包括一个_____函数。

答案:

main@main()@主@主函数@main函数

2、C语言的三种基本结构是指:

顺序结构、选择结构和_____。

答案:

循环结构@循环

3、设a=5,执行表达式"a+=a*=a+a"后a的值是_____。

答案:

100

4、C语言中实现选择结构的语句是if语句和_______。

答案:

switch语句@switch

5、命题"m是不大于100的奇数"用C语言表达式表示为______。

答案:

m<100&&m%2@m<=100&&m%2==1@(m<100)&&(m%2)@(m<=100)&&(m%2==1)

6、根据变量的作用域,在函数外部定义的变量称为_______。

答案:

全局变量

7、设ch为字符型变量,可用表达式_____判断该变量保存字符是否为数字字符。

答案:

ch>='0'&&ch<='9'@(ch>='0')&&(ch<='9')

8、设有定义"inta[10],*p;",语句______将数组元素a[8]的地址赋给指针变量p。

答案:

p=&a[8];@p=a+8;@p=&a[8]@p=a+8

9、设有宏定义"#defineS(x)x*x",则表达式"a=S(n+1)"展开后为_______。

答案:

a=n+1*n+1

10、C语言中声明结构类型的关键字是_______。

答案:

struct

三、程序操作题

1、打开考生文件夹中的程序文件ks1301_1.c,其中fun()函数的功能是求如下表达式:

s=1+1/(1+2)+1/(1+2+3)+1/(1+2+3+4)+…。

程序中共有2处错误,请改正指定的错误行(不得改动程序的其他内容)。

参考代码:

————考生程序代码————

#include

intmain()

{

intn;

floatfun(intn);

printf("Pleaseinputanumber:

");

scanf("%d",&n);

printf("%10.6f\n",fun(n));

return0;

}

floatfun(intn)

{

inti,j,t;

floats;

s=0;

for(i=0;i<=n;i++);//***error***

{

t=0;

for(j=1;j<=i;j++)

t=t+j;

s=s+1/t;//***error***

}

returns;

}

————标准程序代码————

#include

intmain()

{

intn;

floatfun(intn);

printf("Pleaseinputanumber:

");

scanf("%d",&n);

printf("%10.6f\n",fun(n));

return0;

}

floatfun(intn)

{

inti,j,t;

floats;

s=0;

for(i=1;i<=n;i++)//***error***

{

t=0;

for(j=1;j<=i;j++)

t=t+j;

s=s+1/(float)t;//***error***

}

returns;

}

2、打开考生文件夹中的程序文件ks1301_2.c,其中sort()函数的功能是:

用起泡法对n个整数从小到大排序。

程序中共有3处错误,请改正指定的错误行(不得改动程序的其他内容)。

参考代码:

————考生程序代码————

#include

voidsort(intx,intn)//***error***

{

inti,j,t;

for(i=0;i

for(j=1;j

if(x[i]>x[i+1])//***error***

{t=x[j];x[j]=x[j+1];x[j+1]=t;}

}

intmain()

{

inta[10]={0,-1,2,3,-4,5,-6,7,-8,-9};

inti,n=10;

sort(a,n);

printf("outputthesortedarray:

\n");

for(i=0;i<=n-1;i++)

printf("%5d",a[i]);

printf("\n");

return0;

}

————标准程序代码————

#include

voidsort(intx[],intn)//***error***

{

inti,j,t;

for(i=0;i

for(j=0;j

if(x[j]>x[j+1])//***error***

{t=x[j];x[j]=x[j+1];x[j+1]=t;}

}

intmain()

{

inta[10]={0,-1,2,3,-4,5,-6,7,-8,-9};

inti,n=10;

sort(a,n);

printf("outputthesortedarray:

\n");

for(i=0;i<=n-1;i++)

printf("%5d",a[i]);

printf("\n");

return0;

}

3、打开考生文件夹中的程序文件ks1301_3.c,其中fun()函数的功能是:

计算并输出m(包括m)以内能被2或5整除的所有自然数的倒数之和。

例如,在主函数中从键盘给m输入21后,输出为:

s=1.731151。

请将程序代码补充完整,使其实现预期目标。

(不得改动程序的其他内容)

参考代码:

————考生程序代码————

#include

doublefun(intm)

{

intj;

doubletotal=0.0;

for(j=1;______;j++)

if(j%2==0______j%5==0)

total+=______/j;

returntotal;

}

intmain()

{

intm;

doublef;

printf("Inputm:

");

scanf("%d",&m);

f=fun(m);

printf("\ns=%f\n",f);

return0;

}

————标准程序代码————

#include

doublefun(intm)

{

intj;

doubletotal=0.0;

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

if(j%2==0||j%5==0)

total+=1.0/j;

returntotal;

}

intmain()

{

intm;

doublef;

printf("Inputm:

");

scanf("%d",&m);

f=fun(m);

printf("\ns=%f\n",f);

return0;

}

4、打开考生文件夹中的程序文件ks1301_4.c,其中fun()函数的功能是:

判断字符串s中是否有与字符ch相同的字符,若没有则将字符ch添加在字符串的最后,否则什么也不做。

例如,输入test,如果输入a,结果为testa;但如果输入e,则输出结果不变。

请将程序代码补充完整,使其实现预期目标。

(不得改动程序的其他内容)

参考代码:

————考生程序代码————

#include

#include

voidfun(char*s,charch)

{

while(*s&&*s!

=ch)

s++;

if(*s______ch)

{

*s=ch;

______='\0';

}

}

intmain()

{

charstr[80],c;

printf("Pleaseinputastring:

");

gets(str);

printf("Pleaseenterthecharactertosearch:

");

c=getchar();

fun(______);

printf("Theresultis:

%s\n",str);

return0;

}

————标准程序代码————

#include

#include

voidfun(char*s,charch)

{

while(*s&&*s!

=ch)

s++;

if(*s!

=ch)

{

*s=ch;

*(s+1)='\0';

}

}

intmain()

{

charstr[80],c;

printf("Pleaseinputastring:

");

gets(str);

printf("Pleaseenterthecharactertosearch:

");

c=getchar();

fun(str,c);

printf("Theresultis:

%s\n",str);

return0;

}

5、打开考生文件夹中的程序文件ks1301_5.c,编写函数subcopy(),其功能是:

将字符串中从第m个字符开始的全部字符复制为另一个字符串。

例如,若原字符串为"Keepasharpeye.",m值为2,则新的字符串为"epasharpeye."。

参考代码:

————考生程序代码————

#include

//函数subcopy()

intmain()

{

charstr1[20]="Keepasharpeye.",str2[20];

intm;

printf("Pleaseinputm:

");

scanf("%d",&m);

subcopy(str1,str2,m);

printf("%s\n%s\n",str1,str2);

return0;

}

————标准程序代码————

#include

//函数subcopy()

voidsubcopy(char*source,char*dest,intm)

{

inti;

for(i=0;i

source++;

for(;*source!

=0;source++,dest++)

*dest=*source;

*dest='\0';

}

intmain()

{

charstr1[20]="Keepasharpeye.",str2[20];

intm;

printf("Pleaseinputm:

");

scanf("%d",&m);

subcopy(str1,str2,m);

printf("%s\n%s\n",str1,str2);

return0;

}

==END==

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1