您好,欢迎访问三七文档
if语句练习题1.以下不正确的if语句形式是______A)if(xy&&x!=y);B)if(x==y)x+=y;C)if(x!=y)scanf(“%d”,&x),elsescanf(“%d,&y);D)if(xy){x++;y++;}2.以下运算符中优先级最低的是(1),优先级最高的是(2)A)?:B)&&C)+D)!=3.已知intx=10,y=20,z=30;以下语句执行后x,y,z的值是_____if(xy)z=x;x=y;y=z;A)x=10,y=20,z=30B)x=20,y=30,z=30C)x=20,y=30,z=10D)x=20,y=30,z=204.以下if语句语法正确的是_____A)if(x0)printf(“%f”,x)elseprintf(“%f”,-x);B)if(x0){x=x+y;printf(“%f’,x);}elseprintf(“%f”,-x);C)if(x0){x=x+y;printf(“%f”,x);}elseprintf(“%f”,-x);D)if(x0){x=x+y;printf(“%f,x);}elseprintf(“%f”,-x);5.请阅读以下程序:main(){inta=5,b=0,c=0;if(a=b+c)printf(“***\n”);elseprintf(“$$$\n”);}以上程序______A)有语法错不能通过编译B)可以通过编译但不能通过连接C)输出***D)输出$$$6.以下程序的运行结果是______main(){intm=5;if(m++5)printf(“%d\n”,m);elseprintf(“%d\n”,m--);}A)4B)5C)6D)77.当a=1,b=3,c=5,d=4时,执行完下面一段程序后x的值是______if(ab)if(cd)x=1;elseif(ac)if(bd)x=2;elsex=3;elsex=6;elsex=7;A)1b)2c)3d)68.有一个函数关系见下表:xy=x0x-1x=0xx0x+1下面程序段中能正确表示上面关系的是()A)y=x+1;if(x=0)if(x==0)y=x;elsey=x-1;b)y=x-1;if(x!=0)if(x0)y=x+1;elsey=x;c)if(x=0)if(x0)y=x-1;elsey=x;elsey=x+1;d)y=x;if(x=0)if(x0)y=x-1;elsey=x+1;9.以下程序的输出结果是______main(){inta=100,x=10,y=20,okl=5,ok2=0;if(xy)if(!ok1)a=1;elseif(ok2)a=10;a=-1;printf(“%d\n”,a);}A1B0C-1D值不确定10.以下程序输出结果是_______main(){intx=2,y=-1,z=2;if(xy)if(y0)z=0;elsez+=1;printf(“%d\n”,z);A.3B.2C.1D.011.为避免在嵌套的条件语句if-else中产生二义性,C语言规定:else子句总是与___配对.A.缩排位置相同的ifB.其之前最近的ifC.其之后最近的ifD.同一行上的if12.以下不正确的语句为______A.if(xy);B.if(x=y)&&(x!=0)x+=y;C,if(x!=y)scanf(“%d”,&x);elsescanf(“%d”,&y);D.if(xy){x++;y++;}12.阅读以下程序#includestdio.hmain(){floata,b;scanf(“%f”,&a);if(a0.0)b=0.0;elseif((a0.5)&&(a!=2.0))b=1.0/(a+2.0);elseif(a10.0)b=1.0/a;elseb=10.0;printf(“%f\n”,b);}若运行时输入2.0回车,则上面程序的输出结果是_____A)0.000000B)0.500000C)1.000000D)0.25000013.若运行时输入:16回车,则以下程序的运行结果是()#includestdio.hmain(){intyear;printf(“Inputyouyear:”);scanf(“%d”,&year);if(year=18)printf(“you$4.5yuan/xiaoshi”);elseprintf(“your$3.0yuan/xiaoshi”);}14.若运行时输入:2回车,则以下程序的运行结果是()#includestdio.hmain(){charclass;printf(“enter1for1stclasspostor2for2ndpost”);scanf(“%c”,&class);if(class==’1’)printf(“1stclasspostageis19p”);elseprintf(“2ndclasspostageis14p”);}15.若运行时输入:4.4回车,则以下程序的运行结果是()#includestdio.hmain(){floatcostprice,sellingprice;printf(“entercostprice$:”);scanf(“%f”,&costprice);if(costprice=5){sellingprice=costprice+costprice*0.25;printf(“sellingprice(0.25)$%6.2f”,sellingprice);}else{sellingprice=costprice+costprice*0.30;printf(“sellingprice(0.30)$%6.2f”,sellingprice);}}16.以下程序的运行结果是()main(){if(2*2==52*2==4)printf(“T”);elseprintf(“F”);}17.请阅读以下程序:main(){intt,h,m;scanf(“%d”,&t);h=(t/100)%12;if(h==0)h=12;printf(“%d:”,h);m=t%100;if(m10)printf(“0”);printf(“%d”,m);if(t1200||t==2400)printf(“AM”);elseprintf(“PM”);}若运行时输入:1605回车时,程序的运行结果是()18.以下程序实现:输入圆的半径r和运行标志m,按照运行标志进行指定计算.请在()内填入正确的内容.标志运算a面积c周长b二者均计算#definepi3.14159main(){charm;floatr,c,a;printf(“inputmarkacorb&&r\n”);scanf(“%c%f”,&m,&r);if(1){a=pi*r*r;printf(“areais%f”,a);}if(2){c=2*pi*r;printf(“circleis%f”,c);}if(3){a=pi*r*r;c=2*pi*r;printf(“area&&circleare%f%f”,a,c);}}19.若运行时输入:5999回车,则以下程序的运行结果(保留小数后一位)是()main(){intx;floaty;scanf(“%d”,&x);if(x=0&&x=2999)y=18+0.12*x;if(x=3000&&x=5999)y=36+0.6*x;if(x=6000&&x=10000)y=54+0.3*x;printf(“%6.1f”,y);}20.以下程序实现输出x,y,z三个数中的最大者.请在()添入正确内容.main(){intx=4,y=6,z=7;int(1)if(2)u=x;elseu=y;if(3)v=u;elsev=z;printf(“v=%d”,v);}21.以下程序实现:输入三个整数,按从大到小的顺序进行输出.请在()内填入正确内容main(){intx,y,z,c;scanf(“%d%d%d”,&x,&y,&z);if(1){c=y;y=z;z=c;}if(2){c=x;x=z;z=c;}if(3){c=x;x=y;y=c;}printf(“%d,%d,%d”,x,y,z);}22.以下程序对输入的两个整数,按从大到小顺序输出.请在()内填正确内容.main(){intx,y,z;scanf(“%d,%d,”,&x,&y);if(1){z=x;(2)}printf(“%d,%d”,x,y);}23.以下程序对输入的一个小写字母,将字母循环后移5个位置后输出.如’a’变成’f’,’w’变成’b’.请在()填入正确内容#include“stdio.h”main(){charc;c=getchar();if(c=’a’&&c=’u’)(1)elseif(c=’v’&&c=’z’)(2)putchar(c);}24.输入一个字符,如果它是一个大写字母,则把它变成小写,如果是小写,则变成大写,其他字符不变,请在()填正确内容main(){charch;scanf(“%c”,&ch);if(1)ch=ch+32;elseif(ch=’a’&&ch=’z’)(2)printf(“%c”,ch);}25.以下程序的运行结果是()main(){inta,b,c;ints,w,t;s=w=t=0;a=-1,b=3,c=3;if(c0)s=a+b;if(a=0){if(b0)if(c=0)w=a-b;}elseif(c0)w=a-b;elset=c;printf(“%d%d%d”,s,w,t);}26.以下程序的运行结果是()main(){inta,b,c,d,x;a=c=0;b=1;d=20;if(a)d=d-10;elseif(!b)if(!c)x=15;elsex=25;printf(“%d\n”,d);}27.以下程序的运行结果是()#includestdio.hmain(){intx,y=1,z;if(y!=0)x=5;printf(“\t%d\n”,x);if(y==0)x=4;elsex=5;printf(“\t%d\n”,x);x=1;if(y0)if(y0)x=4;elsex=5;printf(“\t%d\n”,x);}28.以下程序的运行结果是()#includestdio.hmain(){intx,y=-2,z=0;if((z=y)0)x=4;elseif(y==0)x=5;elsex=6;printf(“\t%d\t%d\n”,x,z);if(z=(y==0))x=5;x=4;printf(“\t%d\t%d\n”,x,z);if(x=z=y)x=4;printf(“\t%d\t%d\n”,x,z);}29.阅读下面程序:main(){ints,t,a,b;scanf(“%d,%d”,&a,&b);s=1;t=1;if(a0)s=s+1;if(ab)t=s+t;elseif(a==b)t=5;elset=2*s;printf(“s=%d,t=%d”,s,t);}为使输出结果t=4,输入量a和b应满足的条件是()30.请阅读下面程序:main(){ints,t,a,b;scanf(“%d,%d”,&a,&b);s=1;t=1;if(a0)s=s+1;if(ab)t=s+t;elseif(a==b)t=5;elset=2*s;printf(“s=%d,t=%d”,s,t);}为使输出结果s=1,t=5,输入量a和b应满足条件是()31.下面程序根据以下函数关系,对输入的每个x值,计算出y值,在()填正确内容xY2x=10x(x+2)-1x=22xx=-1x-1main(){intx,y;scanf(“%d,&x);if(1)y=x*(x+2);elseif(2)y=2*x;elseif(x=-1)y=x-1;else(3);if(y!=-1)
本文标题:if语句练习题
链接地址:https://www.777doc.com/doc-5127491 .html