C Program – Loops Example – Fibonacci Series up to N terms

In mathematics, the Fibonacci numbers are the numbers in the sequence such as , for the every number after the first two is the sum of the two preceding ones numbers .

Following is the example of Fibonacci series up to 6 Terms

Here number is found by adding up the two numbers before it. As the number 2 is found by adding the two numbers before it (1+1) ,the number 3 is found by adding the two numbers before it as (1+2), the number 5 is by (2+3) &and so on

The sequence Fn of Fibonacci numbers is recursively represented as Fn-1 + Fn-2.

C Program – Loops Example – Fibonacci Series up to N terms

In this program, Variable n is represents total number of terms , variable a and b are temp variable which represents first two number. the initial value of a is set to 1 and b to 0. variable c is to find next number.

First Term , value of c is a+b as (1+0) hence 1.

Second Term , new value of a is b which is 0 and new value of b is c which is 1, hence new value of c is (0+1) hence 1.

Third Term , new value of a is b which is 1 and new value of b is c which is 1 , hence new value of c is (1+1) hence 2.

Fourth Term, new value of a is b which is 1 and new value of b is c which is 2 , hence new value of c is (1+2) hence 3.

Fifth Term, new value of a is b which is 2 and new value of b is c which is 3 , hence new value of c is (2+3) hence 5.

Sixth Term, new value of a is b which is 3 and new value of b is c which is 5 , hence new value of c is (2+3) hence 8.

so on , program calculate up to n terms.

Download Code C-program-code-Fibonacci-Series-up-to-N-terms.c(4 downloads)

Output of program

C-program-code-Fibonacci Series up to N terms