Elites offer unique and original sections on the forum including support for newbies, untapped niches and advanced tutorials, you can follow users journeys and bragging threads too.
Here you will be able to quickly navigate to all the different forum sections. This will save you time if you're in a rush.
I'm going to provide you with a snippet that solves for the Fibonacci sequence using two variables.
Write me a proof that explains why this works.
Alternatively, write your own piece of code using two variables.
static int[] Fib(int length)
{
int x = 0;
int y = 1;
int[] fib = new int[length];
for (int i = 0; i < length; i++)
{
fib[i] = y += x;
i++;
fib[i] = x += y;
}
return fib;
}
Here's a simple Fibonacci sequence that I wrote in my class yesterday. It uses 4 variables but meh. Here it is anyways in good old VB.NET xD:
Code:
Public Class Form1
Dim intNumber As Integer = 1
Dim intFirstPrev As Integer = 1
Dim intSecPrev As Integer = 0
Dim intLoop As Integer
Private Sub btnComp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComp.Click
Do
intLoop = intLoop + 1
calculate()
lstFib.Items.Add(intNumber)
Loop Until intLoop = 10
End Sub
Sub calculate()
intNumber = intFirstPrev + intSecPrev
intSecPrev = intFirstPrev
intFirstPrev = intNumber
End Sub
End Class