• 2022-06-12
    int x,y; if(x<2) y=x; else if(x<10) y=2*x-1; else y=3*x-5;若x=8,则y的值为()
    A: 8
    B: 15
    C: 19
    D: 0
  • B

    举一反三

    内容

    • 0

      执行下列事件过程,y的值为。 Private Sub Command1_Click() x = 3 If x > 10 Then y = x ^ 2 + 3 * x + 2 Else If x > 5 Then y = 3 * x + 2 Else y = 5 End If End If End Sub

    • 1

      若x和y是程序中的两个整型变量,则下列if语句中合法的是________。 A: if(x) y=1; else y=2; B: if(0) y=1 else y=2; C: if(x!=0) then y=1 else y=2; D: if(x!=0) y=1;else y=2;

    • 2

      当x为大于1的奇数时,执行下面的语句后y的值为0的是______。 A: if (x%2 == 1) y = 1 ; else y = 0 ; B: if (x/2 ) y = 1 ; else y = 0 ; C: if (x%2 != 0) y = 1 ; else y = 0 ; D: if ( x%2 == 0 ) y = 1 ; else y = 0 ;

    • 3

      下列语句与y=(x>;0?1:x<;0?-1:0);语句功能相同是( ) A: if (x) if(x>;0) y=1; else if(x<;0) y=-1;else y=0; B: y=-1; if(x>;0) y=1; else y=-1; C: if (x>;0) y=1; else if(x<;0) y=-1; else y=0; D: y=0; if(x>;=0) y=1;else if(x==0) y=0; else y=-1;

    • 4

      若有说明 int x,y;不能实现以下函数关系的程序段是( )[img=145x83]1802ce1f44e61b4.png[/img] A: y=-1;if (x!=0)if(x>0) y=1;else y=0; B: if (x<0) y=-1; else if(x==0) y=0; else y=1; C: y=0; if (x>=0) { if (x>0) y=1; } else y=-1; D: if (x>=0) if(x>0) y=1; else y=0;else y=-1;