Fibonacci Series in C.

What will be the program for Fibonacci  Series in C programming language?

What is Fibonacci Series?
Fibonacci Series is a such type of mathematical series in which sum of previous two number is the next number and the first two number will be 0, and 1. This two number are fixed. This series was developed by an Italian Mathematician named Leonardo .  There is huge story behind this series. That a farmer wants to that how much he can have rabbit in a year with a pair of rabbit. So this series was introduce.
I will not go in details of this story. Lets see the example of this series. 

Example :-
0, 1, 1, 2, 3, 5, 8,  13, 21, 34, 55, 89, 144, 233, ....................
This series is known as Fibonacci Series.

Programming:-

#include<stdio.h>
#include<conio.h>
int main()
{
int num1 = 0, num2 = 1, temp, i, n;  //Data type deceleration.
printf("Enter the last count of the series ");
scanf("%d",&n);  // User input of last count number of the series. 
        printf("Fibonacci Series: ");
for(i=0; i<n; i++)  //Loop for printing series.
{
printf("%d, ",num1);  //printing the number
temp = num1 + num2;
num1 = num2;
num2 = temp;
}
getch();
return 0;
}

Output:-

Output of the above programming

Fig:-1
Logic :-
As a definition of the Fibonacci Series we have to add previous two number to get the next number. So I have taken num1 and num2 for the previous two number and temp as the temporary variable to store the sum of previous two number. And updating the value of num1 as nnum2 and num2 value as temp. All these steps are done under a for loop . For loop executed till the last series count number reached. All this process is done and the Fibonacci Series will get printed. 

If you face any problem then comment on comment section otherwise visit my YouTube Video . Videos are in Hindi language. 

Comments

Post a Comment

Popular posts from this blog

Abundant Number in C Programming || Learning Duniya

Automorphic Number in C Programming || Learning Duniya

How to Print Given Star Pattern