-
[BOJ][C++] 백준 10870 피보나치 수 5CS/Algorithm & Data Structure 2022. 11. 22. 09:50
문제에서 주어진
Fn = Fn-1 + Fn-2 (n ≥ 2) 식을 참고하여 재귀함수를 만들었다.
#include <iostream> using namespace std; int fib(int n) { if (n == 0) return 0; if (n == 1) return 1; else { return fib(n - 1) + fib(n - 2); } } int main() { int N; cin >> N; cout << fib(N); }
'CS > Algorithm & Data Structure' 카테고리의 다른 글
[BOJ][C++] 백준 2447 별찍기 -10 (0) 2022.11.22 [BOJ][C++] 백준 11729 하노이의 탑 이동순서 (0) 2022.11.22 [BOJ][C++] 백준 10872 팩토리얼 (0) 2022.11.22 [BOJ][C++] 백준 1181 단어 정렬 (0) 2022.11.22 [BOJ][C++] 백준 11650 좌표 정렬하기 (0) 2022.11.20