473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How can I code a Fibonacci sequence iteratively

1
how can I write a fibonnaci sequence up n iteratively where n is given by the user and the program must display all the numbers of the sequence up to n.
Jul 30 '09 #1
1 4266
MikeTheBike
639 Expert 512MB
@tlalzo
Hi

I'm not sure if this is whay you want but this writes the sequence down the spreadsheet coulmn up to n.
Expand|Select|Wrap|Line Numbers
  1. Sub FibonnaciNos(ByVal n As Long)
  2.     Dim i As Long
  3.     Dim iRow As Long
  4.     Dim PrevNo As Long
  5.     Dim LastNo As Long
  6.     iRow = 1
  7.     i = 0
  8.     If n >= i Then Cells(iRow, 1) = i
  9.     i = i + 1
  10.     iRow = iRow + 1
  11.     If n >= i Then Cells(iRow, 1) = i
  12.     iRow = iRow + 1
  13.     If n >= i Then Cells(iRow, 1) = i
  14.     iRow = iRow + 1
  15.     PrevNo = i
  16.     LastNo = i
  17.  
  18.     i = LastNo + PrevNo
  19.     Do Until i > n
  20.  
  21.         Cells(iRow, 1) = i
  22.  
  23.         PrevNo = LastNo
  24.         LastNo = i
  25.         i = LastNo + PrevNo
  26.         iRow = iRow + 1
  27.     Loop
  28. End Sub
  29.  
  30. Sub test()
  31.     FibonnaciNos 145
  32. End Sub
??

The numbers 0, 1,1 are straigh code but it didn't seem worth finding a 'clever way' to do that bit !!

MTB
Jul 30 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: snowdy | last post by:
I am using Interactive C with my handboard (68HC11) development system but I've got a problem that I am asking for help with. I am not new to C but learning all the time and I just cant see how to...
62
by: jugaaru | last post by:
How to generate fibonacci mubers in C ?
4
by: Niks | last post by:
Can anybody tell me what a fibonacci search is? any URL for the above information will also do. Thanks for reading.
4
by: dongatopr | last post by:
Could any one help me? (Fibonacci) Computing a Fibonacci sequence, with a numericupdown control and display the result on the listview control. This is on visual studio 2005 (VB). Please help….
0
by: misho | last post by:
Write a C program using the fork() system call that that generates the Fibonacci sequence in the child process. The number of the sequence will be provided in the command line. For example, if 5 is...
6
by: Andrew Tatum | last post by:
I'm having some problems with the below equation. I have no problems when it comes to positives. Negatives create the problem.. C 2 1 4 However, this doesn't work:
1
by: iugamage | last post by:
Help me to write a C program using the fork() system call that that generates the Fibonacci sequence in the child process. The number of the sequence will be provided in the command line. For...
16
by: showellshowell | last post by:
I would like to present an unusual take on computing the Fibonacci sequence using Javascript. Please try out the following link in Firefox (sorry, having problems with other browsers): ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.