Visual Basic - Funcion recursiva Fibonacci
Written by lopezatienza on 29 Octubre 2008 – 14:33 -Primeramente crearemos nuestro proyecto.
Agregamos un tipo Button llamado "btncalcular".
Agregamos un label llamado "lbserie".
Agregamos el siguiente código a "Form1.vb"
Public Class Form1
Private Sub btncalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalcular.Click
Dim max, ant, act As Short
max = 1000
ant = 0
act = 1
lbserie.Visible = True
valor(ant, act) 'Llamo a la funcion
btncalcular.Enabled = False
End Sub
Private Sub valor(ByVal ant As Short, ByVal act As Short)
lbserie.Text = lbserie.Text & ant & " "
If act > 1000 Then
Exit Sub
Else
valor(act, ant + act) 'El numero anterior seria el actual y el actual la suma
End If
End Sub
End Class
Tags: Visual Basic
Posted in Visual Basic .NET |
