- 积分:12
- 财富值:11
- 身份:普通用户
回复:3楼
这我可不懂。。。这个问题太简单了,我给你贴一下代码吧:
Sub chouqu()
Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim m As Integer
Dim a(1 To 4096) As Integer '储存所有求和
Dim b(1 To 29) As Integer '储存所有和出现次数
m = 1
For i = 1 To 8
For j = 1 To 8
For k = 1 To 8
For l = 1 To 8
a(m) = i + j + k + l '此循环计算所有的4096个和
m = m + 1
Next
Next
Next
Next
For i = 1 To 29
For j = 1 To 4096
If a(j) = i + 3 Then b(i) = b(i) + 1
Next
Next '此循环计算所有和出现次数
For i = 1 To 29
Cells(i, 2) = b(i) / 4096 '计算每个和的概率,并输出到B列
Cells(i, 1) = "和为" & i + 3 & "的概率" '结果释义输出到A列
Next
End Sub
- 积分:2
- 财富值:1
- 身份:普通用户
回复:5楼
想试下实验成果,把你式子改了下,改成11取7(8-18里取7个),结果出现for变量已在使用,一时找不到方法,求助攻
Sub chouqu()Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim m As Integer
Dim a(1 To 19487171) As Integer
Dim b(1 To 71) As Integer
m = 8
For i = 8 To 18
For j = 8 To 18
For k = 8 To 18
For l = 8 To 18
For m = 8 To 18
For n = 8 To 18
For o = 8 To 18
a(m) = i + j + k + l + m + n + o
m = m + 1
Next
Next
Next
Next
Next
Next
For i = 1 To 71
For j = 1 To 19487171
If a(j) = i + 55 Then b(i) = b(i) + 1
Next
Next
For i = 1 To 71
Cells(i, 2) = b(i) / 19487171
Cells(i, 1) = "和为" & i + 55 & "的概率"
End Sub