;

C Program To Print the Fibonacci Series


Tutorialsrack 03/11/2019 C

In this C program, we will learn how to write a program to print the Fibonacci series.

Here is the code of the program to print the Fibonacci series.

Code - C Program To Print The Fibonacci Series
/*C Program To Print the Fibonacci Series*/ 
#include<stdio.h>

void main() 
{
  int n1 = 0, n2 = 1, n3, i, number;
  printf("Enter the number of elements:");
  scanf("%d", & number);
  printf("\n%d %d", n1, n2); //printing 0 and 1   
  
   //loop starts from 2 because 0 and 1 are already printed 
  for (i = 2; i < number; ++i)    
  {
    n3 = n1 + n2;
    printf(" %d", n3);
    n1 = n2;
    n2 = n3;
  } 
}
Output

Enter the number of elements:10

0  1  1  2  3  5  8  13  21  34
--------------------------------
Process exited after 3.221 seconds with return value 10
Press any key to continue . . .


Related Posts



Comments

Recent Posts
Tags