kazooie21
November 18th, 1999, 01:38 PM
I need a For...Next statement that will show the square roots of 2 to 12 and only the even numbers.
I also need one that will show the first 10 numbers of the Fibonacci sequence.
kazooie21
L Finch
November 20th, 1999, 07:53 AM
Here's a post from someone else, might help you understand how to approach the following
1.
Re: Fibonacci Numbers
Let's look at what's happening. You have two previous values which
you are adding to get the next value (your first two values are
given of course). So what you need to do, is, in your For Next loop,
store the values in two variables, say PrevVal1 and PrevVal2, as you
loop through. Your new calculated number is passed to the variable
of the previous value (in this case PrevVal2) and that variable's
value is passed to the one before itself (PrevVal1). You also need to
use some checks to determine which of the fibonacci numbers
you're currently on to determine whether the result should be just 1
or whether it's actually calculated.
In pseudocode, it would be as follows:
For CurrentFibNum = 0 to SOMEMAXIMUM
If CurrentFibNum = 0 or CurrentFibNum = 1 then
(Set the first two values in the first two loops)
Set PrevVal1 = PrevVal2
Set PrevVal2 = 1
CurrentVal = 1
Else
(Calculate out the current value and shift the previous ones)
Set CurrentVal = Prev1 + Prev2
Set Prev1 = Prev2
Set Prev2 = CurrentVal
End If
Display CurrentVal or store or whatever
Loop
That should at least give you a starting point. Good luck with it.
2. I would approach the sqaure root question using modulus (mod) to determine whether the number is even, then perfrom sqaure root.