Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 I Need Help On This Fibonacci Sequence
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kid105




PostPosted: Wed Jan 13, 2010 9:55 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Jan 13, 2010 10:21 pm   Post subject: 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


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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: