选择出合法的if语句(设intx,y;)()。
A: if(x!=y)if(x>y)printf("x>y\n"); else printf("x<y\n"); elseprintf("x==y\n");
B: if(x!=y) if(x>y)printf("x>y\n") else printf("x<y\n"); else printf("x==y\n");
C: if(x!=y)if(x>y)printf("x>y\n"); else printf("x<y\n") else printf("x==y\n");
D: if(x!=y) if(x>y) printf("x>y\n"); else printf("x<y\n") else printf("x= =y\n");
A: if(x!=y)if(x>y)printf("x>y\n"); else printf("x<y\n"); elseprintf("x==y\n");
B: if(x!=y) if(x>y)printf("x>y\n") else printf("x<y\n"); else printf("x==y\n");
C: if(x!=y)if(x>y)printf("x>y\n"); else printf("x<y\n") else printf("x==y\n");
D: if(x!=y) if(x>y) printf("x>y\n"); else printf("x<y\n") else printf("x= =y\n");
举一反三
- 下面两条if语句合并成一条if语句为( )。 if(a<=b) x=1; else y=2; if(a>b) printf("**y=%d\n",y); else printf("##x=%d\n",x); A: if(a<=b){ x=1; printf(" B: C: x=%d\n",x); } else{ y=2; printf("**y=%d\n",y); } D: if(a<=b) x=1; printf(" E: F: x=%d\n",x); else y=2; printf("**y=%d\n",y); G: if(a<=b){ x=1; printf("**y=%d\n",y); } else{ y=2; printf(" H: I: x=%d\n",x); } J: if(a>b){ x=1; printf(" K: L: x=%d\n",x); } else{ y=2; printf("**y=%d\n",y); }
- a为非零时显示x,为零时显示y。能完成该功能的语句是 ( ) 。 A: if(a) printf("%d\n",x); else printf("%d\n",y); B: if(!a) printf("%d\n",y); else printf("%d\n",x); C: if (a!=0) printf("%d\n",x); else printf("%d\n",y); D: if(a==0) printf("%d\n",y); else printf("%d\n",x); E: if(a) printf("%d\n",x); else; printf("%d\n",y);
- 以下错误的if语句是( )。 A: if(x>y) z=x; B: if(x==y) z=0; C: if (x !=y) printf("%d", x) else printf("%d", y); D: if(x<y) { x++; y--;}
- 以下程序的输出结果:______________#include "stdio.h"int main(){ int x,y,z; x=1; y=2; z=3; if(x > y) if(x > z) printf("%d",x); else//注意else匹配的if printf("%d",y); printf("%d\n",z);}
- 下列条件语句中,输出结果与其他语句不同的是 A: if(a)printf("%d\ n",x);else printf("%d\n",y); B: if(a==0)printf("%d\n",y);else printf("%d\n",x); C: if(a!=0)printf("%d\ n",x);else printf("%d\n",y); D: if(a==0)printf("%d \n",x);else printf("%d\n",y);