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:
#include <stdio.h>
int main()
{
int i, n, term1 = 0, term2 = 1, next_term;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i)
{
printf("%d, ", term1);
next_term = term1 + term2;
term1 = term2;
term2 = next_term;
}
return 0;
}
Output:
Enter the no. of terms: 12 Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89