为了使运行下列程序后输出4,则输入的a和b值应满足的条件是()
main()
{int s=1,t=1,a,b;
scanf("%d,%d",&a,&b);
if(a>0)
s=s+1;
if(a>b)
t=s+1;
elseif (a==b) t=5;
else t=2*s;
printf("%d\n",t);
}
A、
a〉b
B、
a〈b〈0
C、
0〈a〈b
D、
0〉a〉b
【正确答案】:C
【题目解析】:
main()
{int s=1,t=1,a,b;
scanf("%d,%d",&a,&b);//执行输入命令
if(a>0) //如果a<0时,直接输出t=1;不成立,所以a>0条件成立。
s=s+1 ; //a>0时,执行,得s=2。
if(a>b) //如果a>b条件成立时,t=1+1=2,t的输出为2.,不成立。
t=s+1;
elseif (a==b) t=5; //如果a==b,那么直接输出t=5,此条件不成立
else t=2*s; //以上条件不成立时,即aprintf("%d\n",t); //执行,输出4
}