Let us learn how to print Fibonacci series in C programming language. It is important that we should know **how a for loop works **before getting further with the fibonacci sequence code.

#### What is a Fibonacci sequence?

A Fibonacci series is a sequence of numbers in which the next number is found by adding the previous two consecutive numbers.

**Note: The first two digits in a Fibonacci series is always 0 and 1.**

The first digit in a Fibonacci sequence is** 0** and the second digit as **1**. The next digit or the third element is dependent upon the two preceding elements. The third element is, therefore, the sum of the previous two digits. This addition of previous two digits continues till the limit defined by the user.

The third element is, therefore, the sum of the previous two digits. This addition of previous two digits continues till the limit defined by the user.

#### Example

**0 1 1 2 3 5 8**

**Note:** This code to display Fibonacci series in C programming has been compiled with GNU GCC compiler and developed with gEdit Editor in Linux Ubuntu operating system.

#### Method 1: Print Fibonacci Series in C Programming using For Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<stdio.h> int main() { int limit, first = 0, second = 1, count, third; printf("\nEnter the Elements to be Printed:\t"); scanf("%d", &limit); printf("\n%d\t%d\t", first, second); for(count = 0; count < limit; count++) { third = first + second; printf("%d\t", third); first = second; second = third; } printf("\n\n"); return 0; } |

#### Method 2: C Program To Generate Fibonacci Sequence using While Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include<stdio.h> int main() { int limit, first = 0, second = 1, count, third; printf("\nEnter the Elements to be Printed:\t"); scanf("%d", &limit); printf("\n%d\t%d\t", first, second); count = 0; while(count < limit) { third = first + second; printf("%d\t", third); first = second; second = third; count++; } printf("\n\n"); return 0; } |

#### Method 3: C Program To Print Fibonacci Sequence using Functions

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<stdio.h> void fibonacci(int x, int y, int z, int limit) { for(int count = 0; count < limit; count++) { z = x + y; printf("%d\t", z); x = y; y = z; } } int main() { int limit, first = 0, second = 1, third; printf("\nEnter the Elements to be Printed:\t"); scanf("%d", &limit); printf("\n%d\t%d\t", first, second); fibonacci(first, second, third, limit); printf("\n\n"); return 0; } |

#### Output

There’s a trick with the Fibonacci sequence. The consecutive terms in a fibonacci sequence can be made to convert miles to kilometers. This has been properly demonstrated in **Zeckendorf’s Theorem**.

Let us take 5 and 8, which are consecutive terms in a fibonacci series. But, 5 Miles = 8 Kilometres. Similarly, 8 Miles = 13 kilometres.

In case you get any compilation errors in the above code to print fibonacci sequence in C programming using while loop and for loop or if you have any doubts about it, let us know about it in the comment section below.

Excellent! Thanks!

You’re welcome.

Thanks for multiple methods!

You’re welcome Shanmukha. Our main reason to post multiple methids is to help the students understand the differences between them which will help then to clear basic concepts.

Please provide Codes for Series programs in C.

Sure! You can check for them in the C Programs Menu Header

Its already there on our website. Make a search related to Sum of Series in C our Search bar.

Best Program Updates. Thanks!

You’re welcome. Find more updated C Programs on codingAlpha.

Can we solve Fibonacci Series C Program using Recursion method?

Yes Akshay. Almost all the For Loops, While Loops can be converted into Recursion methods. You just need to understand Recursion properly.

Is this a common interview question? My teachers told that it is frequently asked in interviews.

It depends on the interviewer. But, you should understand the logic of Fibonacci Series. It is not that difficult.

Thanks. You have made this logic for Fibonacci series quite simple to understand.

Perfect code examples for Fibonacci Series in C. Thank you very much.

When we have written this code

first = second;

second = third;

count++;

then why do we need to take the value of first and second as 1 and 0 at initialization in this fibonacci c program?

Thanks for the fibonacci series logic. This is too good program!

Instead of hard coding the first and second values of the fibonacci sequence, why not take the values from the user itself. Just in case he/she wants to begin the fibonacci sequence after a certain number, it would be much easier to code it in C language.

Thanks for this. It is so nice of you to code and publish different methods for every given program. Keep it up.

Nice explanation.

Nice code for Fibonacci sequence. So self explanatory.

Thank you sir you are a man who was born for programming

Why don’t you use recursion method to print the fibonacci series. The code becomes much easier and simpler.

What is a Tribonacci Series? Is it something related to Fibonacci sequence?

Yup. In fibonacci sequence, you take two digits’ sum as the next digit. However, in tribonacci series, you take first digits’s sum for the next digit.