VB将斐波那契数列的前10项写入文件FB.DAT,然后从该文件将数据读取出来并计算合计
答案:1 悬赏:20 手机版
解决时间 2021-03-17 22:37
- 提问者网友:爱了却不能说
- 2021-03-17 19:39
VB将斐波那契数列的前10项写入文件FB.DAT,然后从该文件将数据读取出来并计算合计
最佳答案
- 五星知识达人网友:三千妖杀
- 2021-03-17 20:28
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim n(9) As Integer
n(0) = 0
n(1) = 1
For i = 2 To 9
n(i) = n(i - 1) + n(i - 2)
Next
Open App.Path & "\FB.dat" For Output As #1
For i = 0 To 9
Write #1, "fib(" & i & ")", n(i)
Next
Close #1
End Sub
Private Sub Command2_Click()
Dim n(9) As Integer
Dim j() As String
i = 0
Open App.Path & "\FB.dat" For Input As #1
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, textline ' 读入一行数据并将其赋予某变量。
j = Split(textline, ",")
n(i) = j(1)
i = i + 1
List1.AddItem textline
Loop
Close #1
For i = 0 To 9
Sum = Sum + n(i)
Next
List1.AddItem "合计: " & Sum
List1.AddItem "平均: " & Sum / 10
Dim i As Integer
Dim j As Integer
Dim n(9) As Integer
n(0) = 0
n(1) = 1
For i = 2 To 9
n(i) = n(i - 1) + n(i - 2)
Next
Open App.Path & "\FB.dat" For Output As #1
For i = 0 To 9
Write #1, "fib(" & i & ")", n(i)
Next
Close #1
End Sub
Private Sub Command2_Click()
Dim n(9) As Integer
Dim j() As String
i = 0
Open App.Path & "\FB.dat" For Input As #1
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, textline ' 读入一行数据并将其赋予某变量。
j = Split(textline, ",")
n(i) = j(1)
i = i + 1
List1.AddItem textline
Loop
Close #1
For i = 0 To 9
Sum = Sum + n(i)
Next
List1.AddItem "合计: " & Sum
List1.AddItem "平均: " & Sum / 10
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯