我是编程和处理visual basic 2010概念的初学者,以生成以下Fibonacci系列输出,通过添加两个连续数字来获得下一个数字
我通过创建像bellow
这样的变量尝试过Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Integer = 0
Dim b As Integer = 1
Dim fib As Integer = 0
Do
fib = a + b
a = b
b = fib
Label1.Text = Label1.Text + fib.ToString & ControlChars.NewLine
Loop While fib < 55
End Sub
End Class
答案 0 :(得分:1)
这应该有效
Dim a As Integer = 0
Dim b As Integer = 1
Dim fib As Integer
Do
Label1.Text += a.ToString & ControlChars.NewLine
fib = a + b
a = b
b = fib
Loop While a <= 55
答案 1 :(得分:1)
Private Sub Command1_Click()
Dim x, g, n, i, sum As Integer
n = Val(Text1.Text)
x = 0
y = 1
Print x
Print y
For i = 3 To n
sum = x + y
Print sum
x = y
y = sum
y = sum
Next i
End Sub
答案 2 :(得分:0)
这里是解决方案:
Dim num1 As Integer = 1
Dim num2 As Integer = 1
Dim aux As Integer
Console.Write(num1)
Console.Write(", ")
Console.Write(num2)
Console.Write(", ")
While num1 < 100
aux = num1 + num2
Console.Write(aux)
Console.Write(", ")
num1 = num2
num2 = aux
End While
此印刷品Fibonacci系列至数字100
我希望这能帮到你!