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 prog 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?
check this out:





#include %26lt;stdio.h%26gt;


/* the n-th fibonacci number. */


unsigned int fib(unsigned int n) {


unsigned int a = 1, b = 1;


unsigned int tmp;


while (--n %26gt;= 0) {


tmp = a;


a += b;


b = tmp;


}


return a;


}





main() {


printf("%u", fib(10));


}

yucca

No comments:

Post a Comment