Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fibonacci series using recursion

def fib (n):
  if n == 0 or n ==1:
      return n  
  else:
        return fib(n-2) + fib(n-1)
#n = int(input("please enter a number  "))

n=10
for index,num in enumerate(range(n+1)):
     print(f"F{index} :", fib(num))
Comment

recursive fibonacci

    def fibo2(n):
        if n ==1 or n==0:
            return 1
        else :
            n = n+fibo2(n-1) 
            return n 
    print(fibo2(n1))
Comment

fibonacci recursion

function fib(n) {
    if (n === 1 || n === 0)
        return n

    return fib(n - 1) + fib(n - 2)
}
console.log('fib:', fib(9))		// [Log]: fib: 34
// Time complexity O(2^n)
// Space complexity O(n)
// Since fib(n-1) gets evaluated completely before fib(n-2), there will never be more than n levels of recursion.
Comment

fibonacci series recursion

#include<stdio.h>
int main()
{
int first=0, second=1, i, n, sum=0;
printf("Enter the number of terms: ");
scanf("%d",&n);
//accepting the terms
printf("Fibonacci Series:");
for(i=0 ; i<n ; i++)
{
if(i <= 1)
{
sum=i;
}
//to print 0 and 1
else
{
sum=first + second;
first=second;
second=sum;
//to calculate the remaining terms.
//value of first and second changes as new term is printed.
}
printf(" %d",sum)
}
return 0;
}
Comment

fibonacci using recursion

int fib (int n) {
        if (n < 2)
            return 1;
        return fib(n-1) + fib(n-2);
    }
Comment

fibonacci series using recursion

def fibonacci(n):
    if n <= 1:
          return n
    else:
        return fibonacci(n - 1) + fibonacci(n - 2)

n = int(input())
result = fibonacci(n)
print(result)
Comment

PREVIOUS NEXT
Code Example
Javascript :: extract from a string in javascript 
Javascript :: woocommerce update mini cart ajax 
Javascript :: how to get a due date from current date in javascript 
Javascript :: javascript https post 
Javascript :: javascript check for duplicates in array 
Javascript :: mongodb mongoose with next js connection 
Javascript :: mongoose find multiple conditions 
Javascript :: command to run nextjs project 
Javascript :: faker.js 
Javascript :: how to make a check if 50% of letters are capital in discord js 
Javascript :: how to make a check if letters are capital in discord js 
Javascript :: ant design charts 
Javascript :: postgres boolean column 
Javascript :: Math.avg 
Javascript :: export app react native 
Javascript :: javascript async/await 
Javascript :: p5js left mouse click 
Javascript :: how draw table from json ajax 
Javascript :: form.reset function in javascript 
Javascript :: embedded javascript 
Javascript :: firebase messaging import script 
Javascript :: ip address validation regex angular 
Javascript :: react bootstrap table 
Javascript :: linear gradient react native 
Javascript :: js setattribute download 
Javascript :: object values template literal js 
Javascript :: react router history not defined 
Javascript :: JavaScript next() Method 
Javascript :: js loop through function arguments 
Javascript :: Beautifule JS Console Log 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =