#include #include using namespace std; int fibonacci(int n) { if (n == 0 || n == 1) return 1; else return fibonacci(n-1) + fibonacci(n-2); } int main(int argc, char **argv) { int n; cout << "Suite de Fibonacci" << endl << "Nombre de termes: "; cin >> n; if (n > 0) cout << "F(0) = 1" << endl; if (n > 1) cout << "F(1) = 1" << endl; int f_2 = 1; int f_1 = 1; int f; for (int i=2; i<n; i++) { f = f_1 + f_2; cout << "F(" << i << ") = " << f << ", q = " << float(f) / f_1 << endl; f_2 = f_1; f_1 = f; } cout << "Nombre d'or: " << (1 + sqrt(5)) / 2 << endl; cout << "Suite recursive:" << endl; for (int i=0; i<n; i++) cout << "F(" << i << ") = " << fibonacci(i) << endl; return 0; }
- Saturday
- November 23rd, 2024
- Ajouter un cours