18 lines
423 B
Python
Executable File
18 lines
423 B
Python
Executable File
# Problem Statement: Write a program non-recursive and recursive program to calculate Fibonacci numbers and analyze their time and space complexity.
|
|
|
|
# Non-recursion
|
|
def fibonacci(n):
|
|
fib_series = []
|
|
a = 0
|
|
b = 1
|
|
|
|
for i in range(n):
|
|
fib_series.append(a)
|
|
a = b
|
|
b = a + b
|
|
|
|
return fib_series
|
|
|
|
n = int(input("Enter total numbers to print in fibonacci series:\t"))
|
|
print(fibonacci(n))
|