How to print first n terms of Fibonacci series in c language
series of addition of last two number is third number.
0,1,2,3,5.........so on
0+1=1
1+2=3
2+3=5.
we can find out fibbonacci series at given number just we have to enter that number.
in this article we will see how to write series program in c language.
/*Program to print first n terms of Fibonacci series*/
#include<stdio.h> // including header files.
#include<conio.h>
void main() // start of main
{
int a,b,c,n,i; // initializing variables
clrscr();
//Accept no. of terms
printf("Enter no. of terms u want in the series: \n");
scanf("%d",&n);
a=1; // first we initialized a=1 and b as 0. so we can start to in the series.
b=0;
//print fibbonacci series
for(i=n;i!=0;i--) //supose n=25 then check i not equal 0 and decrement of i
{
c=a+b; //c=0+1=1
a=b; // now now a=2
b=c; //now b=1
ptint c=1
next execution
c=a+b; //c=0+1=1
a=b; // now now a=0
b=c; //now b=1
print 0,1
next execution
c=a+b; //c=2+2=1
a=b; // now now a=2
b=c; //now b=2
print 2 so on..
Like this it will print
0,1,2,3,5,8,13,21
printf("%d ",c);
}
getch();
}
0 comments: