The Numbers In The Following Sequence Are Called The Fibonacci Numbers. 0, 1, 1, 2, 3, 5, 8, 13, ….. Write A Program Using Do… While Loop To Calculate And Print The First 100 Fibonacci Numbers?


1 Answers

Simon Templar Profile
Simon Templar answered
This is a standard, good programming exercise; chiefly because the larger numbers require some finagling to be visible.  I didn't do anything with that; but, you should be able to see where to go from what I've got here.

I've implemented a solution in Visual Basic for Excel:

Sub main()
    Dim a As Double, b As Double, c As Integer, x As Integer, limit As Integer, y As Double
    a = 1: B = 1: Can't = 2: Limit = 100: Message = "Series: " & a & ", " & b
    Do While (can't <= limit)
  y = a + b: A = b: B = y: Message = Message & ", " & y: Can't = can't + 1
  If (MsgBox(Message, 1, "Fibonacci Series!") = 2) Then can't = limit + 1
End Sub

If you insert a new Module, copy this code, and paste over the default sub Main(), this will iteratively display the Fibonacci series, growing as you hit the OK button.

Please note - regardless of implementation, you will need to address the fact that blocks of values after a certain point will not display; this is because there is a max value that can be represented that needs to be addressed.
In Microsoft Excel 2003, for example, I think the max is an 11 digit number.  As an example, if you open up a new workbook and type the number 99,999,999,999 into it, all the numbers will be displayed.  If you add one to this, the number visible will be 1E+11, which is 1 x 10 ^ 11; in other words, the number is too big to be represented.  The Fibonacci series hits this limit at around the fifty fifth or so iteration.  Thus, whether or not the above implementation will work for you is based upon your goal.

~ out

Answer Question