wrote a program to calculate and display the first 20 fibonacci numbers, the sequence goes as follows:
1, 1, 2, 3, 5, 8, 13... (each number is the sum of the previous two numbers)
The problem is that the numbers that get displayed are from 2 onwards , the first and second numbers of the sequence do not get displayed , could someone tell me what needs to be done to correct this?
Code:
private void button1_Click(object sender, EventArgs e)
{
int previousNumber = 1;
int currentNumber = 1;
int nextNumber = 1;
while (currentNumber <= 11000)
{
nextNumber = previousNumber + currentNumber;
previousNumber = currentNumber;
currentNumber = nextNumber;
textBox1.AppendText(Convert.ToString(nextNumber) + " ");
nextNumber++;
}
}
nextNumber++
?, do you really need thenextNumber
variable?)previousNumber
andcurrentNumber
before thewhile
loop?