Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <locale.h>
- using namespace std;
- int fib (int);
- int a[40], i = 2;
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale (LC_ALL, "Russian");
- int n;
- cout << "Введите номпр числа Фибоначи" << endl;
- cin >> n;
- a[0] = 1; a[1] = 1;
- if ((n != 1) && (n != 2))
- {
- fib(n);
- cout << n << "-е число Фибоначчи: " << a[n - 1] << endl;
- }
- else
- cout << "1" << endl;
- system ("pause");
- return 0;
- }
- int fib (int x)
- {
- a[i] = a[i - 1] + a[i - 2];
- if (i < x)
- {
- i++;
- fib(x);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement