Advertisement
35657

Untitled

Mar 22nd, 2024
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int fib(int n) {
  8.     if (n == 1 || n == 2) {
  9.         return 1;
  10.     }
  11.     if (n > 2) {
  12.         return fib(n - 1) + fib(n - 2);
  13.     }
  14. }
  15.  
  16. // ряд Фибоначчи 1 1 2 3 5 8 13 21 34
  17.  
  18. int main() {
  19.     setlocale(LC_ALL, "ru");
  20.  
  21.     cout << fib(9) << endl;
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement