fibonacci series – free C programming tutorial

In this tutorial you will be familiarized with the fibonacci series, and along with it we discuss C language program code to calculate the series.

fibonacci series :

fibonacci series is defined as the series of numbers in which each number is equal to sum of its preceding two numbers.

Example of normal fibonacci-series is given below :

1 , 1 , 2 , 3 , 5 ,8 ,13 , …. and so on.

In mathematical terms,
the sequence Sn of Fibonacci numbers is defined by the relation given as follows :

Sn = Sn-1 + Sn-2

where Sn-1 , Sn-2 are two preceding values of S.


C language program to calculate fibonacci series :

There are two ways to calculate fibonacci-series are explained below :

First way : C language program code to calculate fibonacci-series by using iteration statement that is for loop statement .

# include <stdio.h>
int main()
 {
       int num,count;
       int fact [20]; 

       printf("Enter the value...");
       scanf("%d",&num);

        fact[0] = 1;
        fact[1] =1;
        printf("/n %d...",fact[0]);
        printf("%d...",fact[1]);

         for (count = 2,count<=num,count++) 
              { 
                    fact[count] = fact[count-1] + fact[count-2];
                    printf("%d...",fact[count]);
              }
}

Number of variable in program :

  1. We have to take an array to store the values of series i.e. arr[ size ].
  2. A variable of integer type to store the value entered by user i.e. num.
  3. A variable of integer type to store the counter variables data i.e. count.

When the above code is executed and compiled the following result is obtained.
Output :

Enter the value...5
1...1...2...3...5

Second way : C language program code to calculate fibonacci series by using function along with iteration statement that is for loop statement .

# include <stdio.h>
void fibnum( int );

int main()
 {
       int n,count; 

       printf("Enter the value...");
       scanf("%d",&n);

       void fibnum(n);
 }

void fibnum(int num)
{
  int fib [20];
  fib[0] = 1;
  fib[1] =1;
  printf("/n %d...",fib[0]);
  printf("%d...",fib[1]);          
      for (count = 2,count<=num,count++)
        {               
            fib[count] = fib[count-1] + fib[count-2];              
            printf("%d...",fib[count]);        
        }
}

Number of variable in program :

  1. We have to take an array to store the values of series i.e. arr[ size ].
  2. A variable of integer type to store the value entered by user i.e. num.
  3. A variable of integer type to store the counter variables data i.e. count.

When the above code is executed and compiled the following result is obtained.
Output :

Enter the value...5
1...1...2...3...5

This is all about  the fibonacci series, and along with it we discuss C language program code to calculate the series.
If you have any query please comment below.

Leave a Comment

Your email address will not be published. Required fields are marked *