Advertisement
Nikitka_36

Recursion 3

May 12th, 2014
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <locale.h>
  4.  
  5. using namespace std;
  6.  
  7. int fib (int);
  8. int a[40], i = 2;
  9.  
  10. int _tmain(int argc, _TCHAR* argv[])
  11. {
  12.     setlocale (LC_ALL, "Russian");
  13.  
  14.     int n;
  15.  
  16.     cout << "Введите номпр числа Фибоначи" << endl;
  17.     cin >> n;
  18.     a[0] = 1; a[1] = 1;
  19.  
  20.     if ((n != 1) && (n != 2))
  21.     {
  22.         fib(n);
  23.         cout << n << "-е число Фибоначчи: " << a[n - 1] << endl;
  24.     }
  25.     else
  26.         cout << "1" << endl;
  27.  
  28.     system ("pause");
  29.     return 0;
  30. }
  31.  
  32. int fib (int x)
  33. {
  34.     a[i] = a[i - 1] + a[i - 2];
  35.     if (i < x)
  36.     {
  37.         i++;
  38.         fib(x);
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement