C语言选择结构答案



《C语言选择结构答案》由会员分享,可在线阅读,更多相关《C语言选择结构答案(6页珍藏版)》请在装配图网上搜索。
1、C语言选择构造答案 第二次 选择构造 一 选择题 1. 已有定义:int x=3, y=4, z=5; 那么表达式!(x+y)+z-1 && y+z/2的值是〔 D〕。 A.6 B.0 C.2 D.1 2.为了防止嵌套的if-else语句的二义性,C语言规定else总是与〔C〕组成配对关系。 A.缩排位置一样的if B.在其之前未配对的if C.在其之前未配对的最近的if D.同一行上的if 3. 逻辑运算符两侧运算对象的数据类型〔D〕。&& A.只能是0或1 B.只能是0或非0正数
2、C.只能是整型或字符型数据 D.可以是任何类型的数据 4. 以下运算符中优先级最高的是〔C〕。 A.b) c++; D.if(a>=b) c++; 6.判断char型变量s是否为小写字母的正确表达式是〔C〕。 A.’a’ =’a’) & (s=’a’) && (s=s) 7. x=45, y=’a’, z=0; 那么表达式(x>=z && yb) c=a; a=b; a=2 b=c; b=3 A.a=1, b=2, c=3 B.a=2, b=3, c=3 C.a=2, b=3, c=1 D.a=2, b=3, c
3、=2 9.请阅读以下程序:该程序〔C〕。 #include ”stdio.h” main { int x=-10, y=5, z=0; if (x= z) printf(”***\\n” ); =是赋值 if(x) else printf(”$$$\\n”); } A.有语法错不能通过编译 B.可以通过编译但不能通过连接 C.输出*** D.输出$$$ 10.以下程序的运行结果是〔C〕。 #include ”stdio.h” main { int a=1; if (a++>1) printf(”%d\\n”, a); a=
4、2 else printf(”%d\\n”, --a); } A.0 B.1 C.2 D.3 11.假设a、b、c、d、w均为int类型变量,那么执行下面语句后的w值是〔A〕。 a=1;b=2;c=3;d=4; w=〔a50) printf(”%d”, a); if (a>40) printf(”%d”,a); if (a>30) printf(”%d”,a); } 2. 设int x=9,y=8;表达式x==y+1的结果是___1_____。 3. 定义int x,y;执行y=(x=
5、1,++x,x+2);后, y的值是____4____。 4. 定义int x=10,y,z; 执行y=z=x; x=y==z;后, x的结果是____1____。 5. 以下程序的运行结果是__100______。 #include ”stdio.h” main { int a,b,c,d,e; a=c=1; b=20; d=100; if (!a) d=d++; else if (!b) if (d) d= --d; else d= d--; printf(”%d\\n\\n”, d); } 6.以下程序的功能是判断输入的年份是否是闰年。请在内
6、填入正确内容。 #include ”stdio.h” main { int year, flag; printf(”please input the year to jude whether it is a leap year:”); scanf(”%d”,&year); if (year@0==0) flag=1; else if (【1】) flag=1; /*year%4==0&&year0!=0*/ else 【2】; /* flag=0;*/ if (flag) printf(”%d is a leap year\\n”,year); else pri
7、ntf(”%d is not a leap year!\\n”,year); } 7.以下程序是对用户输入的字母进展大小写转换。请在内填入正确内容。 #include ”stdio.h” main { char ch; printf(”please input a letter:”); scanf(”%c”,&ch); if (【1】) ch=ch+32;/* ch>=’A’ && ch=’a’ && chc) 【2】; printf(”min=%d\\n”,min); } 9.以下程序实现这样的功能:商店卖西瓜,10斤以上的每斤0.15元,8斤以上的每斤0.3
8、元,6斤以上的每斤0.4元,4斤以上的每斤0.6元,4斤以下的每斤0.8元,从键盘输入西瓜的重量和顾客所付钱数,那么输出应付款和应找钱数。请在内填入正确内容。 #include ”stdio.h” main { float weight, money, rate; printf(”the paid money of the client is:”); scanf(”%f”,&money); printf(”the weight of the watermelon is:”); scanf(”%f”,&weight); if (【1】)/* weight>10*/
9、 rate=0.15; else if (weight>8) rate=0.3; else if (weight>6) 【2】;/* rate=0.4*/ else if (weight>4) rate=0.6; 【3】 /*else*/ rate=0.8; printf(”the account payable of the watermelon is %f\\n”, weight*rate); printf(”the change for client is %f\\n”,money-weight*rate); } 10.以下程序段
10、的运行结果是____good! joke____。 #include ”stdio.h” main { char ch1=’a’,ch2=’A’; switch (ch1) { case ’a’: switch (ch2) {case ’A’: printf(”good!\\n”); break; case ’B’: printf(”bad!\\n”); break; } case ’b’: printf(”joke\\n”); } } 11.以下程序运行后的输出结果是______20,0_______。 #include ”stdio.h” main { int x=10, y=20, t=0; if (x==y) t=x; x=y; y=t; printf(”%d,%d\\n”,x,y); } 第 6 页 共 6 页
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。