FibonacciWithRecursion Program
Description
The Fibonacci sequence of numbers start with 0 and 1, then the following number is the addition of two previous numbers.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,144, 233, 377,...
This program inputs an index (position) and then calculates the Fibonacci number at this index using recursion technique.
Associated Concepts:
Recursion
Algorithm:
main method:
Declare variables.
Input an integer index from the keyboard.
Call the recursive method fibonacci() with index as the argument.
Print the result.
fibonacci method definition:
Declare variables.
Input an integer index from the keyboard.
Call the recursive method fibonacci() with index as the argument.
Print the result.
fibonacci method definition:
If the method is call with the base case: index is 0 or index is 1,
it returns the result.
Otherwise, the method returns fibonacci(index - 1) + fibonacci(index - 2).
Otherwise, the method returns fibonacci(index - 1) + fibonacci(index - 2).