内容发布更新时间 : 2024/12/22 14:54:43星期一 下面是文章的全部内容请认真阅读。
If ss(i) <> 0 Then Print ss(i) avera = avera + ss(i) Next i
Picture1.Print avera End Sub
Function ss(n) As Integer Dim i%, tag As Boolean tag = True
For i = 3 To n / 2
If (n Mod i) = 0 Then tag = False Next i
If tag Then ss = n End Function
13:.编一冒泡程序,对已知整数按递减次序排列,用子过程 Sub sort(a())
Dim imin%, i%, j%
For i = 0 To UBound(a) - 1
For j = 0 To UBound(a) - 1 - i If a(j+1) > a(j ) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t End If Next j Next i End Sub
Private Sub Form_Click() Dim b(), i%
b = Array(8, 9, 4, 2, 6) Call sort(b())
For i = 0 To UBound(b) Print b(i); Next i End Sub
14.用选择排序法子过程对已知的若干整数按递增次序排列 Sub sort(a())
Dim imin%, i%, j%
For i = 0 To UBound(a) - 1 imin = i
For j = i + 1 To UBound(a) If a(j) < a(imin) Then imin = j Next j
t = a(i): a(i) = a(imin): a(imin) = t Next i
End Sub
Private Sub Form_Click() Dim b(), i%
b = Array(8, 9, 4, 2, 6) Call sort(b())
For i = 0 To UBound(b) Print b(i); Next i End Sub