A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Fibonacci page! Here, you’ll find a description of the project as well as a list of sample programs written in various languages.
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
For this sample program, each solution should leverage dynamic programming to produce this
list up to the nth term. For instance, ./fib 5
on the command line should output
1: 1
2: 1
3: 2
4: 3
5: 5
In addition, there should be some error handling for situations where the user
doesn’t supply any input or the user supplies input that is not a number
(i.e. ./fib
or ./fib hello
, respectively).
Some tests for your program are:
Description | Input | Output |
---|---|---|
No Input | “Usage: please input the count of fibonacci numbers to output” | |
Empty Input | ”” | “Usage: please input the count of fibonacci numbers to output” |
Invalid Input: not a number | word | “Usage: please input the count of fibonacci numbers to output” |
Sample Input: 0 | 0 | |
Sample Input: 1 | 1 | 1: 1 |
Sample Input: 2 | 2 | 1: 1 2: 1 |
Sample Input: 5 | 5 | 1: 1 2: 1 3: 2 4: 3 5: 5 |
Sample Input: 10 | 10 | 1: 1 2: 1 3: 2 4: 3 5: 5 6: 8 7: 13 8: 21 9: 34 10: 55 |