y=x*x
End If
End If
输出y.
该算法语句的功能是( )
A.输入一个数x,并比较x与0的大小
B.求函数y={■(x+4"," x<0"," @x^2 "," x=0"," @0"," x>0)┤的函数值
C.求函数y={■(x+4"," x<0"," @0"," x=0"," @x^2 "," x>0)┤的函数值
D.以上都不对
解析:此算法涉及复合If语句,分x>0,x=0,x<0三种情况讨论,且相应的y的表达式也不同,故它的功能是求一个分段函数的函数值,易知此函数为y={■(x+4"," x<0"," @0"," x=0"," @x^2 "," x>0"." )┤
答案:C
5.为了在运行下面的算法语句之后输出y=9,键盘输入应该是( )
输入x;
If x<0 Then
y=(x+1)*(x+1)
Else
y=(x-1)*(x-1)
End If
输出y.
A.x=-4
B.x=-2
C.x=4或x=-4
D.x=2或x=-2
解析:当x<0时,由(x+1)·(x+1)=9,得x=-4;
当x≥0时,由(x-1)·(x-1)=9,得x=4,故x=4或x=-4.
答案:C
6.给出下列算法语句:
输入x1,x2;
If x1=x2 Then
y=x1-x2
Else
y=x1+x2
End If
输出y.
如果输入x1=2,x2=3,那么输出的y是( )