Example #1
0
unsigned long int fibbo(unsigned long int i)
{
	if(i==1) return 0;
	else if(i==2) return 1;
	else
		return fibbo(i-1) + fibbo(i-2);
}
int fibbo(int n)
{
if (n==0 || n==1)
return(n);
else
return(fibbo(n-1) + fibbo(n-2));
}
long long int fibbo(long long int *f,int n){

    if(n==1)  return 0;
    else if(n==2) return 1;
    
    else{

        if(f[n]!=0)
            return f[n];

        return f[n]=fibbo(f,n-1)+fibbo(f,n-2);
    }

}
void gfibbo(int n)
{
if (n==0)
return;
else
{
gfibbo(n-1);
printf("\n %d",fibbo(n));
}
}
int main(){


    int t;
    scanf("%d",&t);
    while(t--){

        int n,i;
        scanf("%d",&n);
        long long int f[10000]={0};
        printf("%lld\n",fibbo(f,n+3));        

     }


    return 0;
}
Example #6
0
void main()
{
	unsigned long int n,sum=0,i,term;
	unsigned long int fibbo(unsigned long int);
	clrscr();
	cout<<"How many terms=";
	cin>>n;
	if(n<=0) cout<<"Invalid data\n";
	else
	{
		for(i=1;i<=n;i++)
		{
			term=fibbo(i);
			cout<<term<<' ';
			sum=sum+term;
		}
		cout<<"\nSum="<<sum<<'\n';
	}
	getch();
}