若有以下函数关系
y = 2x x < 0时
y = x + 1 x = 0时
y = x x > 0时
下面程序段能正确表示以上关系的是( )。
(A)
y = 2 * x;
if (x!= 0)
if (x > 0) y = x;
else y = x + 1;
(B)
y = 2 * x;
if (x <= 0)
if (x == 0) y = x + 1;
else y = x;
(C)
if (x >= 0)
if (x > 0) y = x;
else y = x + 1;
else y = 2 * x;
(D)
y = x + 1;
if (x <= 0)
if (x < 0) y = 2 * x;
else y = x;
若有变量定义float x; int y;则正确的switch语句是( )。
(A)
switch (x){
case 1 : printf("**\n");
case 2 : printf("** \n");
}
(B)
switch (x){
case 1~2 : printf("**\n");
case 3~4 : printf("** \n");
}
(C)
switch (1 * y){
case 1 : printf("**\n");
case 2 * y : printf("** \n");
}
(D)
switch (y){
case 1 : printf("**\n");
case 2 : printf("** \n");
}
当a = 1, b = 3, c = 5, d = 4时,执行完下面程序段后x的值为( )。
if (a < b)
if (c < d) x = 1;
else
if (a < c)
if (b < d) x = 2;
else x = 3;
else x = 6;
else x = 7;
(A)1
(B)2
(C)3
(D)6