|
-
Nov 25th, 2003, 02:46 PM
#1
Thread Starter
Lively Member
Displaying a pattern of Fibonacci's sequence ....
hey guys.
i have been trying to display a 25 term pattern displaying the sequence of fibonacci's. for example ... 0, 1, 1, 2,3, 5 ... i can't seem to get it and i was wondering if anyone could help me out with maybe some ideas or just some sort a hint as to how to get it started, thanks.
-
Nov 25th, 2003, 03:21 PM
#2
Frenzied Member
Here's how I wrote it in JavaScript. I doubt it's too hard to convert to VB:
Code:
<html>
<head>
<title>Fibbionacci Sequence</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script>
var a=0
var b=1
var c=0
for (i=0; i<25; i++)
{
c=a+b
document.write(c+",")
b=a
a=c
}
</script>
</body>
</html>
Have I helped you? Please Rate my posts. 
-
Nov 25th, 2003, 03:36 PM
#3
-
Nov 25th, 2003, 03:40 PM
#4
Thread Starter
Lively Member
the downloadable form was good, but i dont need it to ask me how many i want .. like the text box does, but rather to just display 25 automaticaly .. if that is possible?
-
Nov 25th, 2003, 03:46 PM
#5
Frenzied Member
in that case, remove the button and textbox. Make the code run onLoad as opposed to onClick, and change the for loop to:
for i=0 to 25
...
Have I helped you? Please Rate my posts. 
-
Nov 25th, 2003, 04:00 PM
#6
Thread Starter
Lively Member
Private Sub cmdPattern8_Click()
Dim inth As Double
Dim inti As Double
Dim intk As Double
Dim intl As Double
lstDisplay.Clear
For inth = 0 To 25
intk = inth + inti
lstDisplay.AddItem intk
Next inth
End Sub
what's wrong with that? am i just ****ing stupid?
-
Nov 25th, 2003, 04:03 PM
#7
Frenzied Member
Whole code:
VB Code:
Option Explicit
Dim a As Double
Dim b As Double
Dim c As Double
Dim i As Double
Private Sub Form_Load()
lstSeq.Clear
a = 0
b = 1
For i = 0 To 24
c = a + b
lstSeq.AddItem c
b = a
a = c
Next i
End Sub
Where the list is calles lstSeq
Last edited by Acidic; Nov 25th, 2003 at 04:08 PM.
Have I helped you? Please Rate my posts. 
-
Nov 25th, 2003, 04:12 PM
#8
Thread Starter
Lively Member
i'm really new at this and trying to learn, but i really dont understand, i know that i need to use inth, and intk, and that inti is not needed. i only need inth, intk, n intI, and that inth and intk have the correct values, but it's hte intI that is messing me up.
-
Nov 25th, 2003, 04:21 PM
#9
Thread Starter
Lively Member
okay i got it to work! i just need it to start at 0, so make it -1 to 24?
-
Nov 25th, 2003, 04:27 PM
#10
Frenzied Member
using my code:
VB Code:
Option Explicit
Dim a As Double
Dim b As Double
Dim c As Double
Dim i As Double
Private Sub Form_Load()
lstSeq.Clear
a = 0
b = 1
For i = 0 To 24
c = a + b
lstSeq.AddItem c
b = a
a = c
Next i
End Sub
a is set to 0 and b set to 1
It then loops through the loop 25 times, each time making c=a+b which it then adds to the list. Then b=a and a=c. This is so that one the next loop, then will add up to being the next term.
All the i does is to make sure the loop runs through 25 times.
Have I helped you? Please Rate my posts. 
-
Nov 25th, 2003, 04:31 PM
#11
Thread Starter
Lively Member
i finally understand what is happening, but i dont understand how to get 0 to be the first number, i tried different methods that resulted in all 0's and all negatives ...
-
Nov 25th, 2003, 04:35 PM
#12
Thread Starter
Lively Member
nevermind! got it! thanks so much for everything.
-
Nov 25th, 2003, 04:35 PM
#13
Frenzied Member
the only way I can think of is forcing it to be so. Make the first item always 0.
ie, before the loop, at 0 to the list (make sure to run the loop one time less in order to still get 25 terms)
Have I helped you? Please Rate my posts. 
-
Nov 25th, 2003, 04:41 PM
#14
Thread Starter
Lively Member
haha what i did was before the loop began, i made a lstdisplay.additem=a , and then the loop began, i have to do 2 more of these patterns now ... one with this pattern ... 1,3,6,10,5 .. like 1+2=3+3=6+4=10 ... so that each one has the next number added to it, i think i have an idea of what to do nad then the second one is i have to make it add all the digits between 1 and 100 together .... i'm goign to try and do this, if i can't get it, you think you might be able to help me out? i really am learning, that is why i love these forums becuase you just dont give it away, you make people learn .. thanks ...
-
Nov 25th, 2003, 05:42 PM
#15
-
Nov 25th, 2003, 10:36 PM
#16
Thread Starter
Lively Member
for the first of the two, i tried this ....
Private Sub cmdPattern9_Click()
Dim q As Double
Dim l As Double
Dim k As Double
Dim q As Double
lstDisplay.Clear
q = 0
l = 1
For k = 0 To 24
d = q + l
lstDisplay.AddItem d
l = q + 1
q = d
Next k
End Sub
and it didnt work, i mena i think it looks good, but obviously it's not, what is wrong?
-
Nov 25th, 2003, 11:19 PM
#17
Thread Starter
Lively Member
ah, nevermind, holy ****! i got it my own!
you'll feel better when you cannot feel at all ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|