Fibonacci series is a series of numbers in which each number is the sum of its two preceding numbers. The initial two values of the series are 0 and 1. From the 3rd term the values are found by adding the two preceding numbers and then the term is printed.
Here, the program is written to print the terms of the series. The number of terms to be printed is taken as input.
The first few terms of Fibonacci series are:
0, 1, 1, 2, 3, 5, 8, 13, ……………………
INPUT: The number of terms to be printed.
OUTPUT: The terms of the Fibonacci Series.
Step 1: [Taking the input]
Read n [The number of terms to be printed]
Step 2: [Printing the series]
Print a, b
For i=3 to n repeat
[End of ‘for’ loop]
Step 3: Stop.
The time complexity of this program is O(n) where n is the number of terms to be printed.
The space complexity of this program is O(1) as it requires a constant number of memory spaces to display the Fibonacci series.