Generating Fibonacci Sequence

Generating Fibonacci Sequence.

What is a Fibonacci Sequence
The Fibonacci sequence starts with the numbers 0 followed by 1. Each subsequent number is the addition of the previous two numbers. Thus the Fibonaaic sequence looks like below
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and so on.


C++ : Generating Fibonacci Sequence C++14

Python : Fibonacci sequence generator implemented in Python3

def Fibonacci (n) :
    a, b = 0, 1
    print(a, end = ' ')
    print(b, end = ' ')

    for _ in range(n-1) :
        print(int(a+b), end = ' ')
        temp = a + b 
        a = b 
        b = temp
        
def main() :
    n = int(input("Generating upto Fibonacci(n). Enter n : "))
    if n <= 1 : 
       for i in range(n+1) :
           print(i, end = ' ')
    else :
       Fibonacci(n)

if __name__ == "__main__" :
    main()

Output of Fibonacci sequence implemented in Python3

Generating upto Fibonacci(n). Enter n : 20
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 
Generating upto Fibonacci(n). Enter n : 1
0 1 
Generating upto Fibonacci(n). Enter n : 0
0 
Generating upto Fibonacci(n). Enter n : 10
0 1 1 2 3 5 8 13 21 34 55

Copyright © 2019-2020, Algotree.org.
All rights reserved.