DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Fibonacci Function

  • submit to reddit
        This function returns the <i>n</i>th Fibonacci number, though most platforms can go no higher than the 47th.
int Fibonacci(int n) {
 int a = 1, b = 1, c, i;
 for (i=3; i<=n; i++) {c = b; b += a; a = c; }
 return b;