Back
Fibonacci_Khu_De_Quy.cpp
Save
// Fibonacci_Khu_De_Quy.cpp #include
using namespace std; int f(int n) { int a, a1 = 1, a2 = 1; if (n < 3) return 1; for (int i = 3; i <= n; i++) { a = a1 + a2; a1 = a2; a2 = a; } return a; } int main() { int n; cout << "Nhap n: "; cin >> n; cout << "Ket qua: " << f(n); return 0; }