Do you know what the ‘Fibonacci series’ in programming is?

It is when the sum of the preceding two numbers becomes the third number. The series starts with 0 and 1.

So, it becomes,

0,1, 1, 2, 3, 5, 8…..

How do we program this in ‘C’?

Before we work with the entire program, let us first see what is meant by data types in ‘C’.

‘Data types’ in ‘C’:

There are different types of data types in ‘C’ to represent the different number formats. They are:

int (to store whole numbers without decimal point which can be positive, negative or zero, the format to represent it is “%f”))

float(to store decimal values, the format to represent it in program is “%f”)

double(to store decimal values with a longer precision like 1.57627, the format to represent it is “%ld”)

char(to store characters like ‘A’ or ‘a’, the format to represent it is “%c”)

We have also made use of a ‘looping’ structure in this program. We have made use of the ‘for’ loop. A ‘for’ loop iterates over a condition for a specific number of times as mentioned by the final number.

‘For’ loop:

As an example. if I say,

 for(int loop=0;loop<10; loop++)
{
printf "Hello\n");

}

Here, this loop iterates for 10 times and prints the value “Hello” ten times.

Here is the program to create the Fibonacci series of the first 10 numbers….

Note: It is not ChatGPT generated…;)

This is the result of the above code:

Any idea why there are 12 numbers in this series instead of 10? 🙂

This post is part of the BlogchatterHalfMarathon by @blogchatter

(Visited 34 times, 1 visits today)

Related Posts

2 thoughts on “Fibonacci series

  1. This was so nostalgic. I first learnt about the fibonacci series in my school during a computer class and we were learning about arrays in C++. It was my favourite code to execute. It felt like magic!

Leave a Reply