#include<stdio.h>
#include<conio.h>
main()
{
int x,a,b,c,i,sum=0;
a=1;
b=1;
printf("Enter number of terms = ");
scanf("%d",&x);
printf("\n The required Fibonnaci series
of %d terms is : \n\n",x);
if(x==0)
printf("There is no term");
if(x==1)
{
printf("%d\t",a);
sum=sum+1;
}
if(x==2)
{
printf("%d\t%d",a,b);
sum=sum+2;
}
if(x>2)
{
printf("%d\t%d\t",a,b);
for(i=2;i<x;i++)
{
c=a+b;
printf("%d\t",c);
a=b;
b=c;
}
for(i=2;i<x;i++)
{
sum=sum+2+c;
}
}
printf("\n\nThe sum of the
Fibonnaci series of %d terms = %d\n",x,sum);
getch();
}
No comments:
Post a Comment