Write a program to construct a Fibonacci series upto n terms.

Code:-
#include<stdio.h>
#include<conio.h>
int main()
{
int n,pp=0,p=1,nx,i; //pp=previous previous term
     // p=previous term,nx=next term
printf(“Enter the no. of term in fibonacci series”);
scanf(“%d”,&n);
printf(“%d %d “,pp,p);
for(i=2;i<=n;i++)
{
nx=pp+p;
printf(“%d “,nx);
pp=p;
p=nx;
}
return 0;
}
Ouput:-
Enter the no. of term in fibonacci series
5
0 1 1 2 3 5


6 thoughts on “Write a program to construct a Fibonacci series upto n terms.

Leave a Reply

Your email address will not be published.