Advertisement
sheredega

Task #15

Dec 10th, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fib(int n) {
  5.     if (n == 1 || n == 2) {
  6.         return 1;
  7.     }
  8.     return fib(n-1) + fib(n-2);
  9. }
  10.  
  11.  
  12. int main() {
  13.     cout << "Enter n: ";
  14.     int n;
  15.     cin >> n;
  16.     int result = fib(n);
  17.     cout << "Fibonacci value of number " << n << " is " << result;
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement