“Fibbonacci -Serie” Code-Antworten

Fibonacci -Serie

>>> def fib(n):    # write Fibonacci series up to n
...     """Print a Fibonacci series up to n."""
...     a, b = 0, 1
...     while a < n:
...         print(a, end=' ')
...         a, b = b, a+b
...     print()
...
>>> # Now call the function we just defined:
... fib(2000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
Green Team

Fibonacci -Serie

#fibonacci series is special type of sequence
#fibonacci series is somethinng liket this-->
#0,1,1,2,3,5,8,13,21,34,55,89.......
#addition of former two succesive number results in the third element.
#in simple way as given in above series that 0,1,1--> where 0+1=1 e,i; 1
#example: 2,3,5 addition of 2 and 3 results in latter element in sequence e,i 5
8,13,21 :  8 + 13=21
34,55,89:  34 + 55=89
Gr@Y_orphan_ViLL@in##

Fibonacci -Serie

#program to find the fibonacci series
n=int(input('Enter the number of terms in the Fibonacci series :'))
f,s=0,1
print('Fibonacci series =',f,s,sep=',',end=',')
for i in range(3,n+1):
 nxt=f+s
 print(nxt,end=',')
 f,s=s,nxt
#output
Enter the number of terms in the Fibonacci series :7
Fibonacci series =,0,1,1,2,3,5,8,
________________________________________________________________________________
Enter the number of terms in the Fibonacci series :10
Fibonacci series =,0,1,1,2,3,5,8,13,21,34,
________________________________________________________________________________
Enter the number of terms in the Fibonacci series :4
Fibonacci series =,0,1,1,2,
Gr@Y_orphan_ViLL@in##

Fibbonacci -Serie

 1, 1, 2, 3, 5, 8

#include <stdio.h>

void main()
{
    int s1=0,s2=1; //initializing first two numbers 
    int nextNum=0,SumUpto=0;
    printf("\n\n\tPlease enter number up to which print Fibonacci series is required \t");
    scanf("%d",&SumUpto);
    //here assuming user will enter value more than 1 
    //printing first two numbers
    printf("\n\tfibbonacci Series up to %d is ",SumUpto);
    printf("\n\n\t%d  %d",s1,s2);
     for(nextNum=2;nextNum<=SumUpto;)
    {    
        s1=s2;    
        s2=nextNum; 
        printf(" %d",nextNum); 
        nextNum=s1+s2;
    }  
}
Elated Eel

Fibonacci -Serie

// FIBONACCI SERIES
// 0 1 1 2 3 5 8 13 

let number = 7;
// let a=0,b =1,next;
let a=-1,b=1,next;

for(let i=1;i<=number;i++){
  next= a + b;
  a = b;
  b = next
  console.log(next)
}
Abhishek

Ähnliche Antworten wie “Fibbonacci -Serie”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen