| #include <stdio.h> int fib(int n)        //순환-> 개비효율적 {     if (n == 0)         return 0;     if (n == 1)         return 1;     return (fib(n - 1) + fib(n - 2)); } int fib_iter(int n)        //재귀 {     if (n < 2)         return n;     else     {         int i, temp, current = 1, last = 0;         for (i = 2; i <= n; i++)         {             temp = current;             current += last;             last = temp;         }         return current;     } } void main() {     int a, result;     scanf("%d", &a);     result = fib_iter(a);     printf("-> %d \n", result); } | cs | 
'NOTE > Algorithm' 카테고리의 다른 글
| 자료구조) 하노이타워 (0) | 2015.08.25 | 
|---|---|
| 자료구조) 팩토리얼 (0) | 2015.08.25 | 
| 자료구조) Binary_Tree (0) | 2015.08.25 | 
| 자료구조) Tree_Traverse (0) | 2015.08.25 | 
| 자료구조) Graph (0) | 2015.08.25 |