7. Write a program to construct a Fibonacci series upto n terms.
SOURCE CODE:
#include <stdio.h>
int main()
{ int t1=0,t2=1,n,next_term;
printf("enter how many terms you want\n");
scanf("%d",&n);
printf("%d,%d,",t1,t2);
next_term=t1+t2;
for(int i=3;i<=n;i++)
{ printf("%d,",next_term);
t1=t2;
t2=next_term;
next_term=t1+t2;
}
return 0;
}
Comments
Post a Comment