题型:综合题 题类:常考题 难易度:普通
【bj】高中信息技术综合库——枚举算法1
Const n=12
Dim a(1 To n) As Integer
Dim flag(1 To 100) As Boolean
Private Sub Form_Load()
Dim i As Integer, t As Integer
For i=1 To 100
flag(i)=False
Next i
i=1
Do While i <=n
t=Int(Rnd * 100)+1
If Not flag(t) Then
List1.AddItem Str(t)
flag(t)=True
i=i+1
End If
Loop
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, ans As Integer
ans=0
For i=1 To n
For j=i+1 To n
If a(i)+a(j)<=100 Then
If Then
ans=ans+1
flag(a(i)+a(j))= False
End If
Next j
Next i
Label1.Caption="共有"+Str(ans)+"个数!"
End Sub
试题篮