Fibonacci series program using for loop in C Language

The Fibonacci Sequence is the series of numbers as below :
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418,………………

Here is the C Program to understand Fibonacci Series using for loop.

Fibonacci Series using Recursion

Example of Fibonacci Series using for loop in C.

#include<stdio.h>
#include<conio.h>
 
int main()
{
   int n, first = 0, sec = 1, next, c;
 
   printf("Enter the number:\n");
   scanf("%d",&n);
 
   printf("The Fibonacci series are :\n",n);
 
   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d\n",next);
   }
 
   return 0;
}

 

The output of program is :

Enter the number:

8

The Fibonacci series are :

0, 1, 1, 2, 3, 5, 8, 13

 

Author: Meera Academy

Leave a Reply

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