Home » C Programs » C Program for Fibonacci Series

In C, the for loop is used to iterate over statements or parts of programs numerous times. It is commonly used to traverse data structures such as arrays and linked lists. A “For” Loop is used to iterate over a specified block of code a predetermined number of times.

A for loop is used to iterate over a series (that is either a list, a tuple, a dictionary, a set, or a string). This behaves more like an iterator method in other object-oriented programming languages than the for keyword in other programming languages.

The Fibonacci sequence is a series of numbers that begins with a one or a zero, is followed by a one, and continues according to the rule that each number (called a Fibonacci number) is equal to the sum of the two numbers before it.

Setting F0 = 0, F1 = 1, and then applying the recursive algorithm yields the Fibonacci numbers. Fn = Fn-1 + Fn-2 to obtain the remainder. As a result, the sequence is as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,.

```
//C Program For Fibonacci Series
#include <stdio.h>
int main()
{
int i, n;
int t1 = 0, t2 = 1;
int nextTerm = t1 + t2;
printf("Enter the Number");
scanf("%d", &n);
printf("Fibonacci Series: %d, %d, ", t1, t2);
for (i = 3; i <= n; ++i) {
printf("%d, ", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
```

Output:

Enter the Number 5

Fibonacci Series: 0, 1, 1, 2, 3,