Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, n Call A1(n) Close Close End End Sub
Sub A1(a) Dim b%, c%, t% b = 0 c = 1 For i = 1 To a b = b + c c = t t = b Next Print #2, b End Sub
Dim a As Byte
回覆刪除Dim b(10) As Integer
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Input #1, a
Close #1
b(1) = 1
For i = 2 To a
b(i) = b(i - 1) + b(i - 2)
Next i
Open App.Path & "\out.txt" For Output As #2
Print #2, b(a)
Close #2
End
End Sub
佑好,
回覆刪除題目說是※(0<=n<=1000)
但是,你的程式只能做到n=10
所以,錯。
熊掌好,
回覆刪除改了
Dim a as Integer
Dim b(1000) as Double
加起來的數十分可觀
原本想用list來相加但又想到內容型態是字串
Dim a As Integer
Dim b(1000) As Double
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Input #1, a
Close #1
b(1) = 1
For i = 2 To a
b(i) = b(i - 1) + b(i - 2)
Next i
Open App.Path & "\out.txt" For Output As #2
Print #2, b(a)
Close #2
End
End Sub
佑好,
回覆刪除1.這樣改,理論是沒錯,但是,做得到1000嗎?試過嗎?
2.用listbox的字串,有兩個方式可以解決數字,val(字串)==>數值。
另外,就是直接用字串去一個字一個字地「數字加」,加成一個大的數字的字串。
第二個方法就是所謂的「大數加法」,你們前面有一題做「進位」的,就已經是「大數加法」的入門了。改天可以試試。
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt." For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, ins
a = 1: b = 0
For i = 1 To ins - 1
ans = a + b: b = a: a = ans
Next
Print #2, ans
Close
Close
End
End Sub
// 不用用到陣列 就能完成這一題吧
熊掌好
回覆刪除是累加嘛!!?
arro就是這樣寫的
arro好,
回覆刪除程式正確,用三個變數間的變化來解這題,很好。
但是,有沒有試過,可以做到n等於多少呢?
佑好,
以累加來說,也可以。
反正,就是每一項費式數,等於,前兩項費式數的和。
Private Sub Form_Load()
回覆刪除Me.Hide
Dim d(1000) As Long
Open App.Path & "\out.txt" For Output As #2
Open App.Path & "\in.txt" For Input As #1
Input #1, n
d(0) = 0
d(1) = 1
For i = 2 To n
d(i) = d(i - 1) + d(i - 2)
Next
Print #2, d(n)
Close #1
Close #2
End
End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim d(1000) As Long
Open App.Path & "\out.txt" For Output As #2
Open App.Path & "\in.txt" For Input As #1
Input #1, n
Print t(n)
Close #1
Close #2
End
End Sub
Function t(a1)
If a1 > 1 Then t = t(a1 - 1) + t(a1 - 2) Else t = a1
End Function
緣尉好,
回覆刪除程式ok,後面這個解,變數a1,不如用a,比較不容易打錯或誤解。
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, n
Call A1(n)
Close
Close
End
End Sub
Sub A1(a)
Dim b%, c%, t%
b = 0
c = 1
For i = 1 To a
b = b + c
c = t
t = b
Next
Print #2, b
End Sub
2:29