VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-print-first-10-numbers-of-fibonacci-series/

⇱ Program to print first 10 numbers of Fibonacci series - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to print first 10 numbers of Fibonacci series

Last Updated : 23 Jul, 2025

Find the first 10 numbers of Fibonacci series.

The Fibonacci sequence is a sequence where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1.

The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ........

Approach: To solve the problem, follow the below idea:

We can take two variables f1 and f2 to store the first and second term. In order to calculate the next terms, we can take the sum of previous two terms f1 and f2 and then update f1 with f2 and f2 with the new term. Repeat for 10 times to get first 10 numbers of Fibonacci Sequence.

Step-by-step algorithm:

  • Use two variables f1 and f2 and initialize with 0 and 1 respectively because the 1st and 2nd elements of the Fibonacci series are and respectively. 
  • Iterate from 1 to 9 as we have to print first 10 numbers and print f2 then store f2 in temp variable and update f2 with f2 + f1 and f1 as f2.

Below is the implementation of the approach:


Output
0 1 1 2 3 5 8 13 21 34 

Time Complexity: O(10) ~ O(1)
Auxiliary Space: O(1)

Comment
Article Tags: