Dim Q As Long Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do While Not EOF(1) Input #1, Q Print #2, Space(Q) Loop Close #2 Close #1 End End Sub Public Function Space(ByVal Q As Long) As Long If Q = 1 Then Space = 2 Else Space = Space(Q - 1) + Q End If End Function
Dim Q As Long
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
Input #1, Q
Print #2, Space(Q)
Loop
Close #2
Close #1
End
End Sub
Public Function Space(ByVal Q As Long) As Long
If Q = 1 Then
Space = 2
Else
Space = Space(Q - 1) + Q
End If
End Function
BY 小白
小白,你這個公式是線段的,再向前進一步,才是空間的。
回覆刪除input #1,q
sum=2
for i = 1 to q-1
sum = sum + space(i)
next
print #2,sum