Thursday, July 9, 2009

What will b the C code for a prgram that tells us nth term of fibonacci series?

i want a C prog code in which a formula for nth term of fibonacci sereis is there... basically i hav a problem to creat a code for nth term.. its urgent plz....

What will b the C code for a prgram that tells us nth term of fibonacci series?
The value of the Nth term in the fibonacci series is the sum of the N-1 term and the N-2 term.





The 1st term is 1 and the 2nd term is 1. The 3nd term is 2, etc.


So you need a program with three variables; Low_Term, High_Term and New_Term.








(special case code to handle N %26lt; 0, N= 1 or 2)


start by initializing Low_Term and High_Term to 1


in a loop from 3 to N


New_Term = Low_Term + High_Term


Low_Term = High_Term


High_Term = New_Term


No comments:

Post a Comment