C语言期末考试试题南昌航空大学.docx

上传人:b****8 文档编号:9449464 上传时间:2023-05-19 格式:DOCX 页数:15 大小:21.86KB
下载 相关 举报
C语言期末考试试题南昌航空大学.docx_第1页
第1页 / 共15页
C语言期末考试试题南昌航空大学.docx_第2页
第2页 / 共15页
C语言期末考试试题南昌航空大学.docx_第3页
第3页 / 共15页
C语言期末考试试题南昌航空大学.docx_第4页
第4页 / 共15页
C语言期末考试试题南昌航空大学.docx_第5页
第5页 / 共15页
C语言期末考试试题南昌航空大学.docx_第6页
第6页 / 共15页
C语言期末考试试题南昌航空大学.docx_第7页
第7页 / 共15页
C语言期末考试试题南昌航空大学.docx_第8页
第8页 / 共15页
C语言期末考试试题南昌航空大学.docx_第9页
第9页 / 共15页
C语言期末考试试题南昌航空大学.docx_第10页
第10页 / 共15页
C语言期末考试试题南昌航空大学.docx_第11页
第11页 / 共15页
C语言期末考试试题南昌航空大学.docx_第12页
第12页 / 共15页
C语言期末考试试题南昌航空大学.docx_第13页
第13页 / 共15页
C语言期末考试试题南昌航空大学.docx_第14页
第14页 / 共15页
C语言期末考试试题南昌航空大学.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C语言期末考试试题南昌航空大学.docx

《C语言期末考试试题南昌航空大学.docx》由会员分享,可在线阅读,更多相关《C语言期末考试试题南昌航空大学.docx(15页珍藏版)》请在冰点文库上搜索。

C语言期末考试试题南昌航空大学.docx

C语言期末考试试题南昌航空大学

C语言期末考试试题---南昌航空大学

C语言期末考试试题南昌航空大学

一、单选题

(1)若要定义一个具有5个元素的整型数组,以下错误的定义语句是

  A)inta[5]=﹛0﹜;

  B)intb[]={0,0,0,0,0};

  C)intc[2+3];

  D)inti=5,d[i];

(2)以下选项中可用作C程序合法实数的是

  A).1e0B)3.0e0.2  C)E9D)9.12E

(3)有以下程序段

  charname[20];

  intnum;

  scanf("name=%snum=%d",name,&num);

  当执行上述程序段,并从键盘输入:

name=Lilinum=1001<回车>后,name的值为

  A)Lili  B)name=Lili  C)Lilinum=  D)name=Lilinum=1001

(4)if语句的基本形式是:

if(表达式)语句,以下关于“表达式”值的叙述中正确的是

  A)必须是逻辑值B)必须是整数值

  C)必须是正数D)可以是任意合法的数值

(5)若i和k都是int类型变量,有以下for语句

  for(i=0,k=-1;k=1;k++)printf("*****\n");

  下面关于语句执行情况的叙述中正确的是

  A)循环体执行两次

  B)循环体执行一次

  C)循环体一次也不执行

  D)构成无限循环

(6)有以下程序

  #include

  voidmain()

  {intx=1,y=0;

  if(!

x)y++;

  elseif(x==0)

  if(x)y+=2;

  elsey+=3;

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

  }

  程序运行后的输出结果是

  A)3B)2C)1D)0

(7)设有如下函数定义

  intfun(intk)

  {if(k<1)return0;

  elseif(k==1)return1;

  elsereturnfun(k-1)+1;

  }

  若执行调用语句:

n=fun(3);,则函数fun总共被调用的次数是

  A)2B)3C)4D)5

(8)设有定义:

struct{charmark[12];intnum1;doublenum2;}t1,t2;,若变量均已正确赋初值,则以下语句中错误的是

  A)t1=t2;B)t2.num1=t1.num1;

  C)t2.mark=t1.mark;D)t2.num2=t1.num2;

(9)设fp已定义,执行语句fp=fopen("file","w");后,以下针对文本文件file操作叙述的选项中正确的是

  A)写操作结束后可以从头开始读B)只能写不能读

  C)可以在原有内容后追加写D)可以随意读和写

(10)以下叙述中错误的是

  A)C语言的可执行程序是由一系列机器指令构成的

  B)用C语言编写的源程序不能直接在计算机上运行

  C)通过编译得到的二进制目标程序需要连接才可以运行

  D)在没有安装C语言IDE的PC中不能运行C源程序生成的.exe文件

(11)有以下程序

  #include

  voidmain()

  {intx=011;

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

  }

  程序运行后的输出结果是

  A)12B)11C)10D)9

(12)有以下程序

  #include

  voidmain()

  {chars[]="012xy\08s34f4w2";

  inti,n=0;

  for(i=0;s[i]!

=0;i++)

  if(s[i]>='0'&&s[i]<='9')n++;

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

  }

  程序运行后的输出结果是

  A)0B)3C)7D)8

(13)有以下程序

  #include

  voidmain()

  {charb,c;inti;

  b='a';c='A';

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

  {if(i%2)putchar(i+b);

  elseputchar(i+c);

  }printf("\n");

  }

  程序运行后的输出结果是

  A)ABCDEFB)AbCdEfC)aBcDeFD)abcdef

(14)设有定义:

doublex[10],*p=x;,以下能给数组x下标为6的元素读入数据的正确语句是

  A)scanf("%f",&x[6]);B)scanf("%lf",*(x+6));

  C)scanf("%lf",p+6);D)scanf("%lf",p[6]);

(15)有以下程序段

  #include

  voidmain()

  {…

  while(getchar()!

='\n');

  …

  }

  以下叙述中正确的是

  A)此while语句将无限循环

  B)getchar()不可以出现在while语句的条件表达式中

  C)当执行此while语句时,只有按回车键程序才能继续执行

  D)当执行此while语句时,按任意键程序就能继续执行

(16)若有定义语句:

chars[3][10],(*k)[3],*p;,则以下赋值语句正确的是

  A)p=s;B)p=k;C)p=s[0];D)k=s;

(17)有以下程序

  #include

  voidfun(char*c)

  {while(*c)

  {if(*c>='a'&&*c<='z')*c=*c-('a'-'A');

  c++;

  }

  }

  voidmain()

  {chars[81];

  gets(s);fun(s);puts(s):

  }

  当执行程序时从键盘上输入HelloBeijing<回车>,则程序的输出结果是

A)hellobeijingB)HelloBeijing

C)HELLOBEIJINGD)hELLOBeijing

(18)有以下程序

  #include

  voidmain()

  {chara[30],b[30];

  scanf("%s",a);

  gets(b);

  printf("%s\n%s\n",a,b);

  }

  程序运行时若输入:

  howareyou?

Iamfine<回车>

  则输出结果是

A)howareyou?

B)howareyou?

C)howareyou?

Iamfine

D)how  

areyou?

Iamfine

(19)有以下程序

  #include

  intfun(intx,inty)

  {if(x!

=y)return((x+y)/2);

  elsereturn(x);

  }

  voidmain()

  {inta=4,b=5,c=6;

  printf("%d\n",fun(2*a,fun(b,c)));

  }

  程序运行后的输出结果是

  A)3B)6C)8D)12

(20)有以下程序

  #include

  structS

  {inta,b;}data[2]={10,100,20,200};

  voidmain()

  {structSp=data[1];

  printf("%d\n",++(p.a));

  }

  程序运行后的输出结果是

  A)10B)11C)20D)21

二、读程序写结果

(1)阅读下列程序:

#include

voidmain()

{inta;

a=(int)((double)(3/2)+0.5+(int)1.99*2);

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

}

上述程序的输出结果是

(2)阅读下列程序:

#include

intmain()

{inti;intbranch;

doublebonus,bon1,bon2,bon4,bon6,bon10;

bon1=100000*0.1;bon2=bon1+100000*0.075;bon4=bon2+200000*0.05;

bon6=bon4+200000*0.03;bon10=bon6+400000*0.015;

scanf("%d",&i);

branch=i/100000;

if(branch>10)branch=10;

switch(branch)

{case0:

bonus=i*0.1;break;

case1:

bonus=bon1+(i-100000)*0.075;break;

case2:

case3:

bonus=bon2+(i-200000)*0.05;break;

case4:

case5:

bonus=bon4+(i-400000)*0.03;break;

case6:

case7:

case8:

case9:

bonus=bon6+(i-600000)*0.015;break;

case10:

bonus=bon10+(i-1000000)*0.01;

}

printf("奖金是%10.2f\n",bonus);

return0;

}

输入“234000”,上述程序的输出结果是

(3)阅读下列程序:

#include

#include

intmain()

{doublex1,x0,f,f1;

x1=1.5;

do

{x0=x1;

f=((2*x0-4)*x0+3)*x0-6;

f1=(6*x0-8)*x0+3;

x1=x0-f/f1;

}while(fabs(x1-x0)>=1e-5);

printf("Therootofequationis%5.2f\n",x1);

return0;

}

上述程序的输出结果是

(4)阅读下列程序:

#include

intmain()

{inta[11]={1,4,6,9,13,16,19,28,40,100};

inttemp1,temp2,number,end,i,j;

scanf("%d",&number);

end=a[9];

if(number>end)

a[10]=number;

else

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

{if(a[i]>number)

{temp1=a[i];

a[i]=number;

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

{temp2=a[j];a[j]=temp1;temp1=temp2;}

break;

}

}

}

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

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

printf("\n");

return0;

}

输入“50”,上述程序的输出结果是

(5)阅读下列程序:

#include

structstudent

{intnum;charname[20];floatscore;};

intmain()

{structstudentstu[3]={{10101,"Zhang",78},{10103,"Wang",98.5},{10106,"Li",86}};

structstudenttemp;

constintn=3;

inti,j,k;

for(i=0;i

{k=i;

for(j=i+1;j

if(stu[j].score>stu[k].score)

k=j;

temp=stu[k];stu[k]=stu[i];stu[i]=temp;

}

for(i=0;i

printf("%6d%8s%6.2f\n",stu[i].num,stu[i].name,stu[i].score);

printf("\n");

return0;

}

上述程序的输出结果是

(6)阅读下列程序:

#include

intmain()

{voidcopy_string(char*from,char*to);

char*a="ateacher.";

charb[]="astudent.";

char*p=b;

printf("stringa=%s\nstringb=%s\n",a,b);

printf("\ncopystringatostringb:

\n");

copy_string(a,b);

printf("stringa=%s\nstringb=%s\n",a,b);

return0;

}

voidcopy_string(char*from,char*to)

{for(;*from!

='\0';from++,to++)

{*to=*from;}

*to='\0';

}

上述程序的输出结果是

三、改写程序

1.输出结果如图A所示,修改程序,要求

(1)不输出第一行的空行;

(2)“3……”这行输出空行,如图B所示。

#include

intmain()

{

inti,j,n=0;

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

for(j=1;j<=5;j++,n++)

{if(n%5==0)printf("\n");

printf("%d\t",i*j);

}

printf("\n");

return0;

}

图A图B

2.将求分段函数值的功能改写为自定义子函数,在主函数中通过键盘输入数据,调用子函数求函数值并输出。

#include

intmain()

{intx,y;

printf("输入x:

");

scanf("%d",&x);

if(x<1)/*x<1*/

{y=x;

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

}

elseif(x<10)/*1=

{y=2*x-1;

printf("x=%d,y=2*x-1=%d\n",x,y);

}

else/*x>=10*/

{y=3*x-11;

printf("x=%d,y=3*x-11=%d\n",x,y);

}

return0;

}

3.将实参和形参改写为指针方式。

#include

intletter,digit,space,others;

intmain()

{voidcount(char[]);

chartext[80];

printf("inputstring:

\n");gets(text);

printf("string:

");puts(text);

letter=0;digit=0;space=0;others=0;

count(text);

printf("\nletter:

%d\ndigit:

%d\nspace:

%d\nothers:

%d\n",letter,digit,space,others);

return0;

}

voidcount(charstr[])

{inti;

for(i=0;str[i]!

='\0';i++)

if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))

letter++;

elseif(str[i]>='0'&&str[i]<='9')

digit++;

elseif(str[i]==32)

space++;

else

others++;

}

4.第3题中不用全局变量,子函数用数组方式实现。

5.将程序用while语句实现

#include

intmain()

{doubles=0,t=1;

intn;

for(n=1;n<=20;n++)

{t=t*n;s=s+t;}

printf("1!

+2!

+...+20!

=%22.15e\n",s);

return0;

}

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

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

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2