//n번째 숫자 출력.
#include <stdio.h>
int fibonacci(int n)
{
if (n == 1) return 1;
else if (n == 2) return 1;
return fibonacci(n-1)+fibonacci(n-2);
}
int main()
{
int n;
printf("숫자를 입력하세요.\n");
scanf_s("%d", &n);
printf("%d", fibonacci(n));
return 0;
}
'SW 업무 관련 > 기타' 카테고리의 다른 글
[알고리즘][C언어][C++] 더블 링크드 리스트 (0) | 2021.03.15 |
---|---|
[알고리즘][c언어][c++] 링크드 리스트 (0) | 2021.03.10 |
배열 구간의 합 구하기 (0) | 2019.06.08 |
[1] DFS 재귀함수 연습.// 팩토리얼 (0) | 2017.03.05 |