본문 바로가기

Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
더보기
Archives
Total
Today
Yesterday
관리 메뉴

인공지능을 알아가보자

재귀함수를 이용한 피보나치 수열 본문

Emotion

재귀함수를 이용한 피보나치 수열

lis29188 2018. 5. 2. 13:14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
int f(int x)
{
    if (x == 0 || x == 1)
        return x;
    else return f(x - 1+ f(x - 2);
}
int main()
{
    int i, n;
        printf("n:");
        scanf("%d"&n);
            getchar();
            for (i = 0; i <= n; i++)
                printf("%d ", f(i));
            return 0;
}
cs


Comments