A Program to Display Fibonacci Series

In this example, we are giving a program to display fibonacci series up to n number of terms. Fibonacci is a series where a term is the sum of previous two terms. The 1st two terms of the Fibonacci series is 0 followed by 1.


Program to display fibonacci series:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int i, n, term1 = 0, term2 = 1, next_term;
  5. printf("Enter the number of terms: ");
  6. scanf("%d", &n);
  7. printf("Fibonacci Series: ");
  8. for (i = 1; i <= n; ++i)
  9. {
  10. printf("%d, ", term1);
  11. next_term = term1 + term2;
  12. term1 = term2;
  13. term2 = next_term;
  14. }
  15. return 0;
  16. }

Output:

Enter the no. of terms: 12
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89