How to generate a Fib numbers

int fib( n ) // recursive version
{
	
	if ( n < 2 )
		return 1;
	else
		return fib ( n –1 ) + fib ( n –2 );

}

int fib( n ) //iterative version
{
	int f1 =1, f2 = 1;

	if ( n < 2 )
		return 1;	
	for ( i = 1; i < N; i++)
	{
		f = f1 + f2;
		f1= f2;
		f = f1;
	}

	return f;
}
Chitra
Chitra

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in