
-----------------------------------
kid105
Wed Jan 13, 2010 9:55 pm

I Need Help On This Fibonacci Sequence
-----------------------------------
What is it you are trying to achieve? 

1, 1, 2, 3, 5, 8, 13, 21, 34, . . . 
write a program which generates the first n terms of this sequence, where the value of n is entered by the user, given the first two terms of the sequence. scuccessive terms are to be stored in an array. 


What is the problem you are having? 
im kind of stuck on this one i keep getting errors. 


Describe what you have tried to solve this problem 
i have written this program below. 


Turing: 


var number : array 1 .. 10 of int 
var sum := 0 
put skip 
for counter : 1 .. 10 
    put "Enter number ", counter, ": " .. 
    get number (counter) 
end for 
put skip 
put "The ten numbers in order of entry are: " 
put skip 
for counter : 1 .. 10 
    put number (counter) : 5 .. 
end for 
for counter : 1 .. 10 
    sum := sum + number (counter) 
    put sum 
end for

-----------------------------------
DemonWasp
Wed Jan 13, 2010 10:21 pm

RE:I Need Help On This Fibonacci Sequence
-----------------------------------
The sequence is generated by taking the previous TWO numbers and summing them, not the whole sequence:

[code]
1+1   = 2
1+2   = 3
2+3   = 5
3+5   = 8
5+8   = 13
8+13 = 21
13+21= 34
[/code]

Given your existing code, this should be a relatively simple modification. You already have something that lets you ask for a user-input number; all you have to do is do that part twice. You already have something that sums across a group of numbers. All you have to do is find a way to sum only the "current" number and the "previous" number.
