Within a for
loop, I need to get the previous value of the variable i
and the previous value. See, subtracting the variable from -1 and -2 does not work. This is not to get two or a previous position, but to subtract the current value of 1 or 2. What I want is the Fibonacci sequence, but I ask that nobody send me code ready, only if there is any way to get these values of the form as I said I would like to build logic and code myself.
public List<int> fibonacci(int fim)
{
List<int> lista = new List<int>();
int r = 0;
int x = 0;
for (int i = 0; i < fim; i++ )
{
if (i == 0)
{
r = 0;
lista.Add(r);
}
else
{
if (i == 1)
r = 1;
else
r = r ==>> Aqui que estou apanhando
lista.Add(r);
x = r;
}
}
return lista;
}