解答例/線形合同法/Excel VBA
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[練習問題]]
Sub 線形合同法()
Dim m As Long
Dim a As Long
Dim b As Long
Dim x As Long
Dim x2 As Double
Dim avg As Double
Dim i As Integer
m = 65536
a = 997
b = 1
x = 12345
For i = 1 To 100
x = (a * x + b) Mod m
x2 = x / m
Cells(i, 1).Value = Format(x2, "0.0000")
Next
avg = Application.WorksheetFunction.Average(Range("A:A"))
Range("B1") = "平均" & Format(avg, "0.0000")
End Sub
終了行:
[[練習問題]]
Sub 線形合同法()
Dim m As Long
Dim a As Long
Dim b As Long
Dim x As Long
Dim x2 As Double
Dim avg As Double
Dim i As Integer
m = 65536
a = 997
b = 1
x = 12345
For i = 1 To 100
x = (a * x + b) Mod m
x2 = x / m
Cells(i, 1).Value = Format(x2, "0.0000")
Next
avg = Application.WorksheetFunction.Average(Range("A:A"))
Range("B1") = "平均" & Format(avg, "0.0000")
End Sub
ページ名: