#include <stdio.h>


int fibonacci(int n);

int main()

{

    int number;

    int total = 0;

    printf("input the number\n");

    scanf("%d", &number);

    printf("recursive fibonacci = %d \n", fibonacci(number));

}


int fibonacci(int n){

    if (n < 3)

        return 1;

    else return fibonacci(n-2) + fibonacci(n-1);

}


/*C++ 피보나치 합 구하기*/

#include <iostream>

using namespace std;


int fibonacci(int n);


int main()

{

int total = 0;

int n = 0;

for (int i = 0; i <= 5; i++)

{

n = fibonacci(i);

total += n;

}

cout << total << endl;

}


int fibonacci(int n)

{

if (n == 1 || n == 2)

return 1;

else if (n == 0)

return 0;

else

return fibonacci(n - 1) + fibonacci(n - 2);

}

'Programing > Algorithm' 카테고리의 다른 글

프로젝트 오일러 10번  (0) 2015.07.29
프로젝트 오일러 9번  (0) 2015.04.25
순환/재귀 팩토리알 구현  (0) 2015.04.06
3개의 숫자를 내림차순으로 정렬  (0) 2015.04.06
프로젝트 오일러 7번  (0) 2015.02.10
Posted by kimmayer

블로그 이미지
IT 기술들 정리, 독후감을 주로 남깁니다!
kimmayer

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.3
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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함