题型:综合题 题类:常考题 难易度:普通
浙江省高中信息技术 排序算法及程序实现同步练习
以下程序加框处有错,请改正。
Private Sub Command1_Click()
Dim s(1 To 1000)As Single, n As Integer, x As Integer
Dim payment As Single, cost As Single, tmp as Single
‘假设顾客共挑选了n本书,各本书金额数都已存放在数组s中
‘先对n本书按价格降序排序
For i=1 To n-1
x=i
For j=i+1 To n
If Then x=j ’
Next j
If x <> i Then
tmp=s(x)
s(x)=s(i)
s(i)=tmp
End If
Next i
‘降序排序后,每隔两本就是一本可以减免的书
cost=0 : payment=0
For i=1 To n
cost=cost+s(i)
If Then ‘
payment=payment+s(i)
End If
Next i
Label1.Caption=“总金额:” & cost
Label2.Caption=“实付:” & payment
End Sub
试题篮