急!!!大学生程序语言设计(VB)题目,如下,求高手解答!明天考试了!

2025-01-07 19:48:05
推荐回答(1个)
回答1:

'因为<0 与<=10的结果是一样的 所以并起
Select Case X
Case Is <= 10
y = X
Case 10 To 20
y = 10
Case 20 To 40
y = -0.5 * X + 20
End Select

'不嵌套
If X < 10 Then
y = X
ElseIf X > 10 And X <= 20 Then
y = 10
ElseIf X > 20 And a <= 40 Then
y = -0.5 * X + 20
End If
'嵌套
If X <= 20 Then
If X <= 10 Then y = X Else y = 10
ElseIf X > 20 And X <= 40 Then
y = -0.5 * X + 20
End If