求版上的高手幫我健檢一下,我的程式碼錯在哪裡了?
正確的話應該要從A1~C100和 D1的表格都要有值,但是卻只在C1出現了100.6402的值
以下是我的程式碼
Sub Monte_Carlo_PI()
Dim i As Long
Dim j As Long
Dim k As Long
Dim x As Double
Dim y As Double
Dim dist As Double
Dim ma As Long
ma = 100
Randomize
For i = 1 To ma
For j = 1 To ma
For k = 1 To ma
x = Rnd()
y = Rnd()
dist = (x - 0.5) ^ 2 + (y - 0.5) ^ 2
If dist <= 0.25 Then
dist = dist * 4
Else: dist = 0
End If
Next k
Next j
Next i
Worksheets("工作表2").Cells(i, 1) = x
Worksheets("工作表2").Cells(j, 2) = y
Worksheets("工作表2").Cells(k, 3) = dist
Worksheets("工作表2").Cells(1, 4) = WorksheetFunction.Average([C1:C100])
End Sub