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.

PROCESS:

Step 1: [Taking the input]

Read n [The number of terms to be printed]

Step 2: [Printing the series]

Set a<-0

Set b<-1

Print a, b

For i=3 to n repeat

Set c<-a+b

Print c

Set a<-b

Set b<-c

[End of ‘for’ loop]

Step 3: Stop.

for(i=3;i<=n;i++)-----------------------------O(n)

{

c=a+b;

printf("%d ",c);

a=b;

b=c;

}

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.