Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x For i = 0 To x n = x a1 = 1: a2 = 1 For j = 1 To i a1 = a1 * j a2 = a2 * n n = n - 1 Next j ans = a2 / a1 Print #2, ans Next i Close #1 Close #2 End Sub
Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x i = 1 Print #2, 1 Do Until i > x ast = 1: st = 1: q = x For j = 1 To i ast = ast * j st = st * q q = q - 1 Next j Print #2, st / ast i = i + 1 Loop Close #1 Close #2 End Sub
Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x For i = 0 To x Print #2, Cnm(x, i); Next i Close #1 Close #2 End Sub Public Function Cnm(ByVal n As Long, ByVal m As Long) As Long q1 = 1: q2 = 1 For i = 1 To m q1 = q1 * n n = n - 1 q2 = q2 * i Next i Cnm = q1 / q2 End Function
Private Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, N For i = 0 To N Print #2, C(N, i); If i <> N Then Print #2, ","; Next i Close #2 Close #1 End Sub Public Function C(N, i) a = 1 b = 1 For j = 1 To i a = a * (N - j + 1) b = b * j Next j C = a / b End Function
Private Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, q For i = 0 To q Print #2, C(q, i); Next i Close #2 Close #1 End Sub Public Function C(x, y) a = 1 b = 1 For j = 1 To i a = a * (x - y + 1) b = b * y Next j C = a / b End Function
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
For i = 0 To x
n = x
a1 = 1: a2 = 1
For j = 1 To i
a1 = a1 * j
a2 = a2 * n
n = n - 1
Next j
ans = a2 / a1
Print #2, ans
Next i
Close #1
Close #2
End Sub
阿瑋好,
回覆刪除你中間做數學的C(n取i)的地方,差點兒看不懂,不過,反正不是寫給別人看懂的,這個程式OK。
如果要寫給別人看懂的,那個中間的地方,可以改成自訂函數,每次很單純地呼叫myC(n,i),就可以得到回傳的值,也是不錯的。
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
i = 1
Print #2, 1
Do Until i > x
ast = 1: st = 1: q = x
For j = 1 To i
ast = ast * j
st = st * q
q = q - 1
Next j
Print #2, st / ast
i = i + 1
Loop
Close #1
Close #2
End Sub
ㄚ揚好,
回覆刪除程式OK,試函數版吧。
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
For i = 0 To x
Print #2, Cnm(x, i);
Next i
Close #1
Close #2
End Sub
Public Function Cnm(ByVal n As Long, ByVal m As Long) As Long
q1 = 1: q2 = 1
For i = 1 To m
q1 = q1 * n
n = n - 1
q2 = q2 * i
Next i
Cnm = q1 / q2
End Function
函數版
Private Sub Form_Load()
回覆刪除Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, N
For i = 0 To N
Print #2, C(N, i);
If i <> N Then Print #2, ",";
Next i
Close #2
Close #1
End Sub
Public Function C(N, i)
a = 1
b = 1
For j = 1 To i
a = a * (N - j + 1)
b = b * j
Next j
C = a / b
End Function
Private Sub Form_Load()
回覆刪除Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, q
For i = 0 To q
Print #2, C(q, i);
Next i
Close #2
Close #1
End Sub
Public Function C(x, y)
a = 1
b = 1
For j = 1 To i
a = a * (x - y + 1)
b = b * y
Next j
C = a / b
End Function