# Fibonacci Series C Program

## C Program To Print Fibonacci Series

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 C Program Code.

#### What is a Fibonacci Sequence?

A Fibonacci Sequence 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.**

A Fibonacci Series consists of **First Digit** as** 0** and **Second Digit** as **1**. The **Next Digit (Third Element)** is dependent upon the **Two Preceding Elements** (Digits). The Third Element so, the Sum of the Previous Two Digits. This addition of previous two digits continues till the Limit.

#### Example

**0 1 1 2 3 5 8**

#### 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 something to do with the **Zeckendorf’s Theorem**.

5 and 8 are consecutive terms in a Fibonacci Series. Also, 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.