| µ¿ÀûÇÁ·Î±×·¡¹Ö °³³ä | µ¿ÀûÇÁ·Î±×·¡¹Ö »ç·Ê | ºÐÇÒÁ¤º¹°ú µ¿ÀûÇÁ·Î±×·¡¹Ö ºñ±³ |

µ¿Àû ÇÁ·Î±×·¡¹Ö »ç·Ê

¡á ÇǺ¸³ªÄ¡ ¼ö½ÄÀ» °è»êÇÏ´Â ÇÔ¼ö

FnÀÌ Fn-1°ú Fn-2 Áï, ÃÖ±Ù¿¡ °è»êµÈ µÎ ÇǺ¸³ªÄ¡ ¼öÀÇ ÇÕÀ̶ó´Â »ç½Ç¿¡ Âø¾ÈÇÏ¸é ´ÙÀ½°ú °°Àº ÇÁ·Î±×·¥ÀÌ °¡´É

-------------------------------------------------

unsigned  int  fibonacci( unsigned  int  n )

{       unsigned  int  i,  last,  next_to_last,  answer;

         if( n <= 1 )

             return  1;

 

         last = next_to_last = 1;

         for( i = 2 ;  i <= n ;  i++)

         {

             answer = last + next_to_last;

             next_to_last = last;

             last = answer;

         }

 

         return answer;

}

-------------------------------------------------

¼±Çü(O(N)) ÇǺ¸³ªÄ¡¼ö °è»ê ÇÔ¼ö