Skip to content

deepak14ri/The-fibonacci-Sequence-using-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

The-fibonacci-Sequence-using-Java

The Fibonacci Sequence The Fibonacci sequence appears in nature all around us, in the arrangement of seeds in a sunflower and the spiral of a nautilus for example.

The Fibonacci sequence begins with fibonacci(0)=0 and fibonacci(1)=1 as its first and second terms. After these first two elements, each subsequent element is equal to the sum of the previous two elements.

Programmatically:

fibonacci(0)=0 fibonacci(1)=1 fibonacci(n)=fibonacci(n-1)+fibonacci(n-2)

Given n, return the nth number in the sequence.

n=5 The Fibonacci sequence to 6 is fs=[0,1,1,2,3,5,8].With zero-based indexing,fs[5]=5. Problem description Complete the code in the editor.

Input: Contains a single integer,n.

Output: int: the nth element in the Fibonacci sequence

Constraints 0<n<=30

Print the absolute difference between the sums of the two diagonals of the matrix as a single integer.

Sample Input 3 Sample Output 2

Explanation The Fibonacci sequence begins as follows:

fibonacci(0)=0 fibonacci(1)=1 fibonacci(2)=(0+1)=1 fibonacci(3)=(1+1)=2 fibonacci(4)=(1+2)=3 fibonacci(5)=(2+3)=5 fibonacci(6)=(3+5)=8

In the sequence above, fibonacci(3) is 2.