1,代码中有错误 for x=j+1 to 31 》》》》for x=k+1 to 31---------------------------------
3条回答
1楼 · 2022-11-11 21:31.采纳回答
我做了个选号程序,需要源代码可以HI我。
加载中...
2楼-- · 2022-11-11 21:27
1,代码中有错误 for x=j+1 to 31 》》》》for x=k+1 to 31 ------------------------------------------- 你的意思就是算位置,既然是组合,肯定就用组合公式推导了。 反推:(为少打点字,以6选3为例) k为6 公式C(m,n)为m选n组合
Private Sub Command3_Click() Dim n As Long, m As Long Dim i%, j%, k%, x%, y%, z% Dim a%, b%, c%, d%, e%, f%
a = 3: b = 8: c = 12: d = 15: e = 19: f = 26 For i = 1 To 28 For j = i + 1 To 29 For k = j + 1 To 30 For x = k + 1 To 31 For y = x + 1 To 32 For z = y + 1 To 33 n = n + 1 If i = a And j = b And k = c And x = d And y = e And z = f Then m = n Next Next Next Next Next Next Print n, m End Sub
我做了个选号程序,需要源代码可以HI我。
for x=j+1 to 31 》》》》for x=k+1 to 31
-------------------------------------------
你的意思就是算位置,既然是组合,肯定就用组合公式推导了。
反推:(为少打点字,以6选3为例)
k为6
公式C(m,n)为m选n组合
f(x,y,z)=C(6,3)-[ C((k-x),3) + C((k-y),2) + C((k-z),1) ]
正推就自己推吧!
Mother asked .
A. were there any cheaper shoes
B. there are some cheaper shoes
C. if there were any cheaper shoes
D. if there are any cheaper shoes
写代码求哈(原问题中for x=j+1 to 31要改成for x=k+1 to 31):
Private Sub Command3_Click()
Dim n As Long, m As Long
Dim i%, j%, k%, x%, y%, z%
Dim a%, b%, c%, d%, e%, f%
a = 3: b = 8: c = 12: d = 15: e = 19: f = 26
For i = 1 To 28
For j = i + 1 To 29
For k = j + 1 To 30
For x = k + 1 To 31
For y = x + 1 To 32
For z = y + 1 To 33
n = n + 1
If i = a And j = b And k = c And x = d And y = e And z = f Then m = n
Next
Next
Next
Next
Next
Next
Print n, m
End Sub
一周热门 更多>