Discuss Scratch

saifulazwan
New Scratcher
5 posts

fibonacci series

can u guys help me solve this question

the sequence of number 0,1,2,3,5,8,13 …….

the 1st two numbers are 0 and 1. write a program that calculates the nth term of fibonacci series, when n is entered by the user
quaris
Scratcher
42 posts

fibonacci series

add0toFibbonacciadd1toFibbonaccirepeatuntilkeyanypressed?additemlengthofFibbonacci-1ofFibbonacci+itemlengthofFibbonacciofFibbonaccitoFibbonacci

Adding the second-to-last item of the list to the last item of the list and adding it to the list

P.S. There's actually two 1's: 0,1,1,2,3,5…

Last edited by quaris (Nov. 25, 2015 17:17:38)

quaris
Scratcher
42 posts

fibonacci series

VoltageGames
Scratcher
1000+ posts

fibonacci series

quaris wrote:

add0toFibbonacciadd1toFibbonaccirepeatuntilkeyanypressed?additemlengthofFibbonacci-1ofFibbonacci+itemlengthofFibbonacciofFibbonaccitoFibbonacci

Adding the second-to-last item of the list to the last item of the list and adding it to the list

P.S. There's actually two 1's: 0,1,1,2,3,5…
Actually, there's a much simpler way.
Zro716
Scratcher
1000+ posts

fibonacci series

If you're looking to get the nth term in the series, try this:
definefibnifn>2fibn-1 recursive calladdresulttostackfibn-2changeresultbyitemlastofstackdeletelastofstackelseadd1tostack push 1 to the stackwhenclickedfib5sayresult
saifulazwan
New Scratcher
5 posts

fibonacci series

tq guys for the response given , but my lecturer said that he wants the 3rd number must be 3, means that 0 and 1 considered as 1st number in sequence ? can help me ?
drmcw
Scratcher
1000+ posts

fibonacci series

Use the code you have been given but add 1 to the parameter n.

Last edited by drmcw (Nov. 26, 2015 09:51:05)

monstermash3
Scratcher
1000+ posts

fibonacci series

This will make it start with 1 and 2:
whenclickeddeletealloffibonaccinumbersadd1tofibonaccinumbersadd2tofibonaccinumbersifanswer=1thensay1elseifanswer=2thensay2elserepeatanswer-2additemlastoffibonaccinumbers+itemlengthoffibonaccinumbers-1offibonaccinumberstofibonaccinumberssayitemlastoffibonaccinumbers

Last edited by monstermash3 (Nov. 27, 2015 01:26:08)

deck26
Scratcher
1000+ posts

fibonacci series

saifulazwan wrote:

tq guys for the response given , but my lecturer said that he wants the 3rd number must be 3, means that 0 and 1 considered as 1st number in sequence ? can help me ?
If your lecturer wants the third numgber to be 3 you're going to have to start with 1,2

Everything else is decided by the starting values.
sathvikrias
Scratcher
500+ posts

fibonacci series

here are 2 ways
whenclickedsetxto0setyto1setzto0addztolist fibonacciforeversetxtoy+zaddxtolistsetytox+zaddytolist fibonaccisetztoy+xaddztolist fibonacci

this way only uses a list, but is a teeny bit slower in scratch 2.0

whenclickedadd0tolist fibonacciadd1tolist fibonacciforeveradditemlengthoffibonacci-0offibonacci+itemlengthoffibonaccioflisttofibonacci

Last edited by sathvikrias (Oct. 9, 2020 19:22:51)

Powered by DjangoBB