if (a) d=d-10; else if (!b) if (!c) x=15; else x=25;
printf(“d=%d\\n”,d); }
3.# include “stdio.h” main()
{int s,t,a,b; scanf(“%d,%d”,&a,&b); s=1; t=1; if (a>0) s=s+1; if (a>b) t=s+t;
else if (a= =b) t=5; else t=2*s;
printf(“s=%d,t=%d\\n”,s,t); }
4.# include “stdio.h” main()
{ int x=1,y=0; switch(x)
{ case 1: switch(y)
{ case o: printf(“first\\n”);break; case 1: printf(“second\\n”);break; }
case 2: printf(“third\\n”); } }
5.分别写出以下程序在输入-10或5或10或30后的执行结果 # include “stdio.h” main()
{int x,c,m; float y; scanf(“%d”,&x); if (x<0) 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=%g\\n”,y);
else printf(“error!\\n”); }
6.# include “stdio.h” main()
{int a=2,b=7,c=5; switch (a>0)
{ case 1: switch (b<0)
{case 1: printf(“@”);break; case 2: printf(“!”);break; }
case 0: switch (c==5)
{case 0: printf(“*”);break; case 1: printf(“#”);break; default: printf(“$”);break; }
default: printf(“&”); }
printf(“\\n”); }
7.# include “stdio.h” main() {int n=0; while (n<=4) switch(n) {case 0: ;
case 1: printf(“%d”,n);
case 2: printf(“%d”,n++);break; default: printf(“**”,n++); } }
8.# include “stdio.h” main()
{int a,b,c; a=b=c=0;
if (++a||b++&&c++) printf(“%d,%d,%d”,a,b,c);
else printf(“OK”); }
9.执行完下列程序段后,x,y的值为什么? int x=1,y=1; int m,n; m=n=1; switch(m)
{ case 0: x=x*2; case 1: { switch (n)
{ case 1: x=x*2;
case 2: y=y*2; break; case 3:x++; } }
case 2: x++;y++;
case 3: x*=2;y*=2;break; default : x++;y++; }
四、编程题
1、编写一程序,输入三个数,判断是否构成三角形。 2、编写一个程序,完成两个数的四则运算。
第三部分 参考答案
一、单项选择
1.B 2.C 3.B 4.B 5.A 6.D 7.C 8.A 9.A 10.A 11.C 12.D 14.C 15.B 16.D 17.B 18.A 19.C 20.C 二、填空
1. do{ }while(P); , for(表达式1;表达式2;表达式3 ), while(P){ }
2. switch 3. 分支,循环 4. 离它最近的下一个语句中 5. 循环,switch 6. 循环,循环体内continue以下语句的执行 7. (year%4= =0&&year0!=0)|| (year@0= =0) 8.不会 9.不会 10.不会,能 11.会,null不等于NULL 12. k1=-1,k2=65535 13. x=1234.568,y=1.23e+03 14. 65,41,157,00000111 15. m= = n && m>1
16. 0.000000 17. c!=0 18. 5.0,4,c=3 三、阅读程序,写出运行结果
1. end 2. D=20 3. s=2,t=3 4. first
{ float x,y,z; scanf (“%f%f%f”,&x,&y,&z);
if (a+b>=c && a+c>=b && b+c>=a ) printf(“true\\n”); else printf(“false\\n”); }
2.#include
{ float x,y; char op; printf (“输入表达式:”);
scanf (“%f%c%f”,&x,&op,&y);
13.B switch (op)
{ case ?+?: printf(“%g%c%g=%g\\n”,x,op,y,x+y); break; case ?-?: printf(“%g%c%g=%g\\n”,x,op,y,x-y); break; case ?*?: printf(“%g%c%g=%g\\n”,x,op,y,x*y); break; case ?/?: if(y!=0.0)
printf(“%g%c%g=%g\\n”,x,op,y,x/y); else
printf(“除0错误”); break;
default: printf(“表达式有误”); } }
第四部分 循环
一、单项选择
1.下面程序段中的循环执行( )次. int x=20;
do{ x/=2; } while (x - -);
(A)4次 (B)3次 (C)5次 (D)不确定 2.在1题中,若能退出循环,则退出循环后,x的值为( ) (A)0 (B)0.375 (C) – 0.625 (D) – 1 3.下面程序段中循环的循环体( ). int n=1;
do{ n=+ +n*5;} while(n=10);
(A)执行1次 (B)执行2次 (C)不执行 (D)执行无限次 4.执行下面程序后的输出结果为( ) int x , y, z; x=20;y=40;z=60; while(x y - =4; z/=2; printf(“%d,%d,%d”,x,y,z); (A)40,36,30 (B)32,28,7 (C)32,28,30 (D)32,28,7.5 5.下面程序段在执行完成后,a的值为( ) int j=0,k=0,a=0; while(j<2) { j+ +; a=a+1; k=0; while(k< =3) {k + +; if (k%2! =0) continue; a=a+1; } a=a+1; } (A)4 (B)6 (C)8 (D)10 6.执行下面程序段后,x和y的值分别为( ) int x=1,y=1; int m,n; m=1;n=1; switch (m) {case 0: x=x*2; case 1: {switch(n) { case 1:x=x*2; case 2:y=y*2;break; case3:x+ +; } } case 2 : x+ +; y+ +;