数学题1~33个数字,要每6个数
下面是设计的程序。
核心是如何把33个数中取3个的所有组合都搞出来。
Private Sub Command5_Click()
Dim a(1 To 6) As Integer
k = 6: duoshao = 0
For i = 1 To 6: a(i) = i: Next
Do
he = 0
For i = 1 To 6: he = he + a(i): Next
If he = 100 Then
For i = 1 To 6: Text1。 Text = Text1。Text + Str(a(i)) + " ": Next
Text1。Text = Text1。Text + vbC...全部
下面是设计的程序。
核心是如何把33个数中取3个的所有组合都搞出来。
Private Sub Command5_Click()
Dim a(1 To 6) As Integer
k = 6: duoshao = 0
For i = 1 To 6: a(i) = i: Next
Do
he = 0
For i = 1 To 6: he = he + a(i): Next
If he = 100 Then
For i = 1 To 6: Text1。
Text = Text1。Text + Str(a(i)) + " ": Next
Text1。Text = Text1。Text + vbCrLf
duoshao = duoshao + 1
Me。
Caption = Str(duoshao)
Me。
Refresh
DoEvents
End If
a(6) = a(6) + 1
Do
k = 7
For i = 1 To 6
If a(i) = i + 28 Then
k = i
If i = 1 Then
k = 0
Exit Do
End If
a(i - 1) = a(i - 1) + 1: a(i) = 0
End If
Next
If k = 7 Then Exit Do
Loop
If k = 0 Then Exit Do
For i = 1 To 6
If a(i) = 0 Then a(i) = a(i - 1) + 1
Next
Loop
End Sub
运行后得到答案: 19995
。收起