Question: if ( n < 0 ) return - 1 ; / / declare int variable term 1 , term 2 and nextTerm / / initialize

if(n<0)
return -1;
//declare int variable term1,term2 and nextTerm
//initialize term1,term2 with 0 and 1
int term1=0,term2=1,nextTerm;
//for loop iterate n times
for(int i=1;i<=n;i++)
{
//nextTerm is calculated by adding term1 and term2
nextTerm=term1+term2;
//set term2 value as new term1
term1=term2;
//set nextTerm value as new term2
term2=nextTerm;
}
return term1;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!