
正文
斐波那契vb.net 斐波那契数列python
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net 斐波那契数列 求大神帮助!!!
代码斐波那契vb.net:
Imports System.IO
Public Class feibo
Function fancibo(ByVal n As Integer) As Long
If n = 2 Then
Return 1
Else
Return fancibo(n - 1) + fancibo(n - 2)
End If
End Function
Sub CreateData(ByVal max As Integer)
Dim fs As New FileStream("fb.txt", FileMode.Create, FileAccess.Write)
Dim mywriter As New BinaryWriter(fs)
Dim i As Integer
For i = 1 To max
mywriter.Write(fancibo(i))
Next i
mywriter.Close()
End Sub
Sub ReadandDealData()
Dim fs As New FileStream("fb.txt", FileMode.Open, FileAccess.Read)
Dim myreader As New BinaryReader(fs)
Dim i, s As Integer
Dim tot As Long
Dim avg As Single
i = 0 : s = 0 : tot = 0 : avg = 0.0
ListBox1.Items.Clear()
While fs.Position fs.Length
s = myreader.ReadInt64()
ListBox1.Items.Add(s)
tot += s
i += 1
End While
avg = tot / i
ListBox1.Items.Add("数据斐波那契vb.net的总和:" tot)
ListBox1.Items.Add("数据斐波那契vb.net的平均值:" avg)
myreader.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
CreateData(15)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ReadandDealData()
End Sub
End Class
相关问答
Q1: 用vb输出斐波那契数列前20项的所有偶数
Public Class Form1
Dim arraa%(19)
Dim i%, j%
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
arraa(0) = 1
arraa(1) = 1
arraa(2) = 1
Label2.Text = "1 1 1"
For i = 3 To 19
arraa(i) = arraa(i - 1) + arraa(i - 2) + arraa(i - 3)
Label2.Text = Label2.Text " " arraa(i)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For i = 3 To 19
If arraa(i) Mod 2 = 0 Then Label4.Text = Label4.Text " " arraa(i)
Next
End Sub
End Class
把图片上面的 数字改动 质数改成偶数就可以了
貌似有一点 没有偶数 呢
Q2: 请问Vb.net编程代码,不要C语言的,我看不懂啊?
Imports System
Module Program
Sub Main()
Dim n As Integer
n=6
Console.WriteLine("{0}!={1}",n,fact(n))
n=10
For i As Integer=1 To n
Console.Write("{0}{1}",fibo(i),IIF(n=i,vbCrLf,","))
Next
Console.Write("按任意键继续。。。 ")
Console.ReadKey(True)
End Sub
' 递归算阶乘
Function fact(n As Long) As Long
If 0=n OrElse 1=n Then Return 1
Return n*fact(n-1)
End Function
' 递归算斐波那契数列
Function fibo(n As Long) As Long
If 1=n OrElse 2=n Then Return 1
Return fibo(n-1)+fibo(n-2)
End Function
End Module
斐波那契vb.net的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于斐波那契数列python、斐波那契vb.net的信息别忘了在本站进行查找喔。








