选择结构程序设计习题

上传人:cl****1 文档编号:584923876 上传时间:2024-09-01 格式:PPT 页数:21 大小:276.57KB
返回 下载 相关 举报
选择结构程序设计习题_第1页
第1页 / 共21页
选择结构程序设计习题_第2页
第2页 / 共21页
选择结构程序设计习题_第3页
第3页 / 共21页
选择结构程序设计习题_第4页
第4页 / 共21页
选择结构程序设计习题_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《选择结构程序设计习题》由会员分享,可在线阅读,更多相关《选择结构程序设计习题(21页珍藏版)》请在金锄头文库上搜索。

1、选择结构选择结构1.C语言中,逻辑值假用0表示,逻辑真用 表示。2.下面的程序为求分段函数y的值,将程序填写完整:填空题#include void main( )int x,y;printf(Please input x:n); scanf(%d,&x);if(x1) y=x;else if( (1) ) (2) ; else (3) ; printf(y=%dn,y); 3.以下程序对输入的一个小写字母,将字母循环后移6个位置后输出。如a变成g,w变成c。请在空中填入正确内容。 #include void main( ) char c; c=getchar(); if(c=a&c=u&c=z

2、) (2) ; putchar(c); 填空题1.为了避免嵌套的if-else语句的二义性,C语言规定else总是与 组成配对关系。 A、缩排位置相同的if B、其之前未配对的if C、其之前未配对的最近的if D、同一行上的if2.选择出合法的if语句(设int x,a,b,c;) 。 A、if (a=b) x+; B、if (a=b) x+; C、if (ab) x+; D、if (a=b) x+;单项选择题3.选择出合法的if语句(设int x,y;) 。 A、if (x!=y) if (xy) printf(xyn); else printf(xy) printf(xyn) else

3、printf(xy) printf(xyn); else printf(xy) printf(xyn); else printf(x0) y=1; else y=0; B、if (x=0) if (x0) y=1; else y=0; else y=-1; C、y=0; if (x=0) if (x0) y=1; else y=-1; D、y=-1; if (x0) y=1; else y=0;5.执行下列程序,输入为1的输出结果是 (1) ,输入为3的输出结果是 (2) 。 #include void main( ) int k; scanf(%d,&k);单项选择题 case 1: pri

4、ntf(%dn,k+); case 2: printf(%dn,k+); case 3: printf(%dn,k+); case 4: printf(%dn,k+); break; default: printf(Full!n); (1)A、1 B、2 C、2 3 4 5 (竖排) D、1 2 3 4(竖排)(2)A、3 B、4 4(竖排) C、3 4(竖排) D、4单项选择题6.假定等级和分数有以下对应关系:等级:A 分数:85-100 等级:B 分数:60-84 等级:C 分数:60以下对于等级grade输出相应的分数区间,能够完成该功能的程序段是 。A、switch(grade) ca

5、se A:printf(85-100n); case B:printf(60-84n); case C:printf(60以下n); default:printf(等级错误!n); 单项选择题B、 switch(grade) case A:printf(85-100n); break; case B:printf(60-84n); case C:printf(60以下n); default:printf(等级错误!n); C、switch(grade) case A:printf(85-100n); break; case B:printf(60-84n); break; caseC:prin

6、tf(60以下n); default:printf(等级错误!n); 单项选择题 D、switch(grade) case A:printf(85-100n); break; case B:printf(60-84n); break; case C:printf(“60以下n”); break; default:printf(等级错误!n); 1.以下程序的执行结果是 。 #include void main( ) int a,b,c; a=2;b=3;c=1; if (ab) if (ac) printf(%dn,a); else printf(%dn,b); printf(endn); 程

7、序的运行结果:阅读下面程序,写出程序的运行结果2.以下程序的执行结果是 。 #include void main() int a,b,c,d,x; a=c=0; b=1; d=20; if (a) d=d-10; else if (!b) if (!c) x=15; else x=25; printf(d=%dn,d); 程序的运行结果:阅读下面程序,写出程序的运行结果3.以下程序在输入5,2之后的执行结果是 。 #include void main( ) int s,t,a,b; scanf(%d,%d,&a,&b); s=1; t=1; if (a0) s=s+1; if (ab) t=s

8、+t; else if (a=b) t=5; else t=2*s; printf(s=%d,t=%dn,s,t); 程序的运行结果:阅读下面程序,写出程序的运行结果4.以下程序的执行结果是 (1) 、 (2) 。 #include void main( ) int x=1,y=0; switch(x) case 1: switch(y) case 0:printf(firstn);break; case 1:printf(secondn);break; case 2:printf(thirdn); 阅读下面程序,写出程序的运行结果5.执行以下程序,输入-10的结果是 ,输入5的结果是 ,输入

9、10的结果是 ,输入30的结果是 ,输入20的结果是 。 #include void main( ) int x,c,m; float y; scanf(%d,&x); if (x0) c=-1; else c=x/10; switch(c) case 1:y=0;break; case 0:y=x;break; case 1:y=10;break; case 2: case 3:y=-0.5*x+20;break; default:y=-2; if (y!=-2) printf(y=%gn,y); else printf(errorn); 阅读下面程序,写出程序的运行结果 习题习题 习题习题 习题习题 习题习题 习题习题 习题习题 习题习题

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 研究生课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号