“Серия Фибоначчи” Ответ

Фибоначчи в Яве

// Java program for the above approach
  // divyaraj
class GFG {
  
    // Function to print N Fibonacci Number
    static void Fibonacci(int N)
    {
        int num1 = 0, num2 = 1;
  
        int counter = 0;
  
        // Iterate till counter is N
        while (counter < N) {
  
            // Print the number
            System.out.print(num1 + " ");
  
            // Swap
            int num3 = num2 + num1;
            num1 = num2;
            num2 = num3;
            counter = counter + 1;
        }
    }
  
    // Driver Code
    public static void main(String args[])
    {
        // Given Number N
        int N = 10;
  
        // Function Call
        Fibonacci(N);
    }
}
Ugly Unicorn

Серия Фибоначчи

>>> 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 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##

Серия Фибоначчи

#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##

Серия Фибоначчи

#include <iostream>
using namespace std;

int main()
{
    cout<<"Fibonacci series upto 10 terms :- "<<endl;
 
    int a = 0, b = 1;
    int next;

    for(int i=0; i<10; i++)
    {
        if(i==0) {
             cout<<a<<" ";
             continue;
        }

        else if(i==1)
        {
            cout<<b<<" ";
            continue;
        }

        next = a + b;
        a=b;
        b=next;

        cout<<next<<" ";
    }

    return 0;
}
Coding Ninjas

Серия Фибоначчи

// 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

Ответы похожие на “Серия Фибоначчи”

Вопросы похожие на “Серия Фибоначчи”

Смотреть популярные ответы по языку

Смотреть другие языки программирования