Fibonacci Series

Fibonacci Series


Fibonacci Series is special type of series in which any number is sum of its previous two numbers.
Fibonacci Series is: 0, 1, 1, 2, 3, 5, 8, 13, 21, .....
Fibonacci Series always starts with 0.
Here, we are going to find Fibonacci Series for first n terms.

Let's see program:

#include<stdio.h>
void main()
{
int f0, f1, f2, i, n;
printf("Enter number upto which you want Fibonacci series: ");
scanf("%d",&n);
printf("%d   %d   ",f0,f1);  //Assuming user enters n>2//
for(i=3;i<=n;i++)
{
f2=f0+f1;
printf("%d   ",f2);
f0=f1;
f1=f2;
}
}

Explanation:
Here, it will take value from user as n and iterate upto n-2 times to give required Fibonacci Series.
It must iterate n-2 times because first 2 digits are entered by us.

Output:



No comments:

Post a Comment