vb.net 斐波那契数列 求大神帮助?。。?/h2>代码斐波那契vb.net:
Imports System.IO
Public Class feibo
Function fancibo(ByVal n As Integer) As Long
【斐波那契vb.net 斐波那契数列python】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.Positionfs.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
用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 = "111"
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
Ifarraa(i) Mod 2 = 0 Then Label4.Text = Label4.Text""arraa(i)
Next
End Sub
End Class
把图片上面的 数字改动 质数改成偶数就可以了
貌似有一点 没有偶数 呢
请问Vb.net编程代码,不要C语言的,我看不懂?。?/h2>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的信息别忘了在本站进行查找喔 。
推荐阅读
- js的值动态传给html,js怎么传值到后端
- 抖音小游戏冒险大闯关下载,抖音上玩大冒险的软件
- ppt如何让字突然消失,怎么让ppt里的字体不变
- python卷积不用函数 python中卷积函数
- chatGPT用的什么算法,twap算法
- jquery弹跳效果,jquery实现弹窗表单
- 剑术格斗游戏规则视频大全,剑术格斗技巧
- c语言怎么引用函数 c语言调用函数
- go语言指针怎么赋值,golang指针赋值