# C Program to find sum of two numbers

#include<stdio.h>
#include<conio.h>
void main{
int fib1=0,fib2=1,term,fibo,i;
clrscr();
printf("Enter the number of terms:");
scanf("%d",&term);
printf("\Fibonacci series for %d terms is as follows:",term);
for(i=0;i {
if(i<=1)
{
fibo=i;
}
else
{
fibo=fib1+fib2;
fib1=fib2;
fib2=fibo;
}
if(i==term-1)
printf("%d",fibo);
else
printf("%d,",fibo);
}
getch();
}

## Explanation:

The above program will print the Fibonacci series of n number of terms. 'term' is a variable which contains the value of number of terms of a Fibonacci series. The for loop will be executed until the i is less than the term. In the loop Fibonacci series will be calculated. We can understand this process by given example:

term=4,fib1=0,fib2=1
i=0
i<(term=4),True
iteration 1:
i<=1,True
fibo=i=0
i=(term-1=3),False
so print 0,
i=i+1=1
i<(term=4),True iteration2:
i<=1,True
fibo=i=1
i=(term-1=3),False
so print 1,
i=i+1=2
i<(term=4),True
iteration3:
i<=1,False
so fibo=fib1+fib2=1
fib1=fib2 i.e fib1=1
fib2=fibo i.e fib2=1
i=(term-1=3),False
so print 1,
i=i+1=3
i<(term=4),True
iteration 4:
i<=1,False
so fibo=fib1+fib2=2
fib1=fib2 i.e fib1=1
fib2=fibo i.e fib2=2
i=(term-1=3),True
so print 2
i=i+1=4
i<(term=4),False
loop break
Finally we get Fibonacci series as:0,1,1,2
The output of the above program is given below: