VB程序设计习题

2025-02-22 11:18:31
推荐回答(3个)
回答1:

1.
x = Val(InputBox("Input X: "))
If x < 10 Then y = Abs(x)
If x <= 20 Then y = Sqr(3 * x - 1)
If x > 20 Then y = 3 * x + 2
Debug.Print y

2.
x = Val(InputBox("Input X: "))
If x < 10 Then
y = Abs(x)
ElseIf x <= 20 Then y = Sqr(3 * x - 1)
ElseIf x > 20 Then y = 3 * x + 2
End If
Debug.Print y

3.
x = Val(InputBox("Input X: "))
select case x
case x < 10
y = Abs(x)
case <= 20
y = Sqr(3 * x - 1)
case else
y = 3 * x + 2
end select
Debug.Print y

回答2:

1
x=val(inputbox("输入:"))
if x<10 then y=abs(x)
if x>=10 and x<=20 then y=3*x-1
if x>20 then y=3*x+2
?y

2
if x<10 then
y=abs(x)
elseif x<=20 then
y=3*x-1
else
y=3*x+2
endif
?y

3
select case x
case is<10
y=abs(x)
case 10 to 20
y=3*x-1
case else
y=3*x+2
end select
?y

回答3:

(1) if
endif
if
endif
if
endif
(2)if
else if
else
endif
(3)select case x