有以下程序: #include<stdio.h> main() {double x=2.0,y; if(x<0.0)y=0.0; else if((x<5.0)&&(!x)) y=1.0/(x

admin2019-02-02  43

问题 有以下程序:
    #include<stdio.h>
    main()
    {double x=2.0,y;
      if(x<0.0)y=0.0;
      else if((x<5.0)&&(!x))
        y=1.0/(x+2.0);
      else if(x<10.0)y=1.0/x;
      else y=10.0;
      printf("%f\n",y);
    }
    程序运行后的输出结果是(    )。

选项 A、0.000000
B、0.250000
C、0.500000
D、1.000000

答案C

解析 本题重点考查if语句,变量x和y均为double类型,由于变量x赋值为2.0,因此执行if((x<5.0)&&(!x)),即条件为0,继续执行if(x<1 0.0),条件为真,即执行y=1.0/x;。依据printf()函数输出类型,f是以小数形式输出单/双精度实数。故C选项正确。
转载请注明原文地址:https://kaotiyun.com/show/zERp777K
0

最新回复(0)