网站建设资讯

NEWS

网站建设资讯

斐波那契vb.net 斐波那契数列前100项

vb.net 斐波那契数列 求大神帮助!!!

代码:

创新互联公司提供成都网站建设、网站制作、网页设计,成都品牌网站建设1元广告等致力于企业网站建设与公司网站制作,10余年的网站开发和建站经验,助力企业信息化建设,成功案例突破上1000+,是您实现网站建设的好选择.

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("数据的总和:" tot)

ListBox1.Items.Add("数据的平均值:" 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 = "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

把图片上面的 数字改动 质数改成偶数就可以了

貌似有一点 没有偶数 呢

请问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求和

斐波那契数列的发明者,是意大利数学家列昂纳多·斐波那契.

斐波那契数列指的是这样一个数列:1、1、2、3、5、8、13、21、……

下面是前1000项斐波那契数列的和的VB代码:

Private Sub Command1_Click()

Dim a As Integer

Dim b As Integer

Dim c As Integer

Dim S As Long

Dim i As Integer

a = 1

b = 1

S = 2

For i = 3 To 1000

c = a + b

S = S + c

a = b

b = c

Next i

Print S

End Sub

vb怎么编写斐波那契数列?

Sub s()

n = Val(InputBox("input n:"))

ReDim arr(1 To n)

arr(1) = 1

arr(2) = 1

Debug.Print 1; 1;

For i = 3 To n

arr(i) = arr(i - 1) + arr(i - 2)

Debug.Print arr(i);

Next

End Sub

使用VB如何编写程序求第n项斐波那契数列的值

Function F(n As Long) As Long

If n 2 Then

F = F(n - 1) + F(n - 2)

Else

F = 1

End If

End Function

Private Sub Command1_Click()

Cls

Dim I As Long

I = Val(inputbox("n=?"))

Print "第 " I " 项斐波那契数列值为:" F(i)

End Sub


当前标题:斐波那契vb.net 斐波那契数列前100项
文章分享:http://njwzjz.com/article/hjhsod.html