C Program for Fibonacci Series

Summary: in this tutorial, you will learn how to develop a C program for Fibonacci series using recursion and iteration techniques.

Introduction to Fibonacci numbers

C Program for Fibonacci SeriesIn mathematics, the Fibonacci numbers, or Fibonacci series,  are the numbers that are in the following sequence:

0,1,1,2,3,5,6,13,21,34,55,89,…

The first number in the Fibonacci sequence is 0, the second number is 1. The subsequent number is the result of the sum of the previous two e.g., the third number 1 = 1+0, the fourth number 2=1+1, the fifth number 3 = 2+1.

The Fn number is defined as follows:

Fn = Fn-1 + Fn-2,

with the seed values:

F0 = 0, F1 = 1.

C Programs for Fibonacci Series

C Program for Fibonacci series using recursion

The first simple approach of developing a function that calculates the nth number in the Fibonacci series using a recursive function. The following is the Fibonacci series program in c:

Now if you enter 15, the program will display the following output:

C Program for Fibonacci series using iteration

The Fibonacci series program using recursion technique is less efficient if you want to display a long series because the number of function calls increase and the chance of a stack overflow error may occur.

The following is the program that displays the Fibonacci series using iteration technique:

In this tutorial, you have learned how to develop a C program for Fibonacci series using recursion and iteration techniques.

  • Was this tutorial helpful ?
  • YesNo