Saturday, July 2, 2022

Fibonacci Numbers (Recursion)

 Fibonacci Numbers (Recursion)

Problem Statement
Given an integer N, find the Nth number in the fibonacci series. Consider 0 and 1 to be the seed values.

In the fibonacci series, each number (Fibonacci number) is the sum of the two preceding numbers. The series with 0 and 1 as seed values will go like -
0, 1, 1, 2, 3, 5 and so on..

static long  Fibonacci(long  n) 
    { if(n==0){
return 0;
}
else if (n==1)
{
return 1;
}
return Fibonacci(n-1)+Fibonacci(n-2);

  //Enter your code here
    }

No comments:

Post a Comment

ads vert

Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody

  Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody < table >      < thead >    ...