logo CodeStepByStep logo

fibonacci

Related Links:
Author: Mehran Sahami (on 2019/10/23)

Write a function named fibonacci that displays all the numbers in the Fibonacci Sequence up to a given max, starting with 0. The Italian mathematician Leonardo Fibonacci devised the Fibonacci sequence as a way to model the growth of a population of rabbits. The first two terms in the sequence are 0 and 1, and every subsequent term is a sum of the previous two terms. (The Fibonacci sequence has numerous applications in computer science and shows up in surprising places. It's used to compute logarithms, index and retrieve data, and as a building block in some route-planning algorithms.) Output from the example call of fibonacci(10000):

Fibonacci sequence up to 10000:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765

This program should continue as long as the value of the term is less than the maximum value.

Note that the maximum term value is specified using an integer parameter.

Function: Write a C function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.