/*
prints fibonacci series upto a given term.
This code made a different approach for printing terms.
*/
#include<stdio.h>
void main()
{
int n,c,a=0,b=1;
printf("enter number of terms : ");
scanf("%d",&n);
c=n/2+n%2;
printf("Fibonacci Series : \n\n");
while(c>0)
{
if(n%2==1 && c==1)
printf("%d ",a);
else
printf("%d %d ",a,b);
a=a+b;
b=a+b;
c--;
}
printf("\n");
}
No comments:
Post a Comment