Q5. Write a code to print fibonacci series

Solution :- This program is about giving a length N and the task is to print the Fibonacci series upto n terms.

Fibonacci Sequence :- The Fibonacci sequence is a sequence consisting of a series of numbers and each number is the sum of the previous two numbers. For Example :- 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …….

Algorithm of Fibonacci Series

START
Step 1->Declare variables i, a, b, nextTerm
Step 2->Initialize the variables, a=0, b=1, and nextTerm = 0
Step 3->Enter the number of terms of Fibonacci series to be printed
Step 4->Repeat below steps n times
-> print the value of a
-> nextTerm = a + b
-> a = b
-> b = nextTerm
-> increase value of i each time by 1
STOP

Code of Fibonacci Series

Output

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number