Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void init();
- int fibonacci(int n);
- int main() {
- setlocale(LC_ALL, "Russian");
- init();
- system("pause");
- return 0;
- }
- void init() {
- cout << "Введите n-ое число Фибоначчи (меньшее 40): ";
- int n;
- cin >> n;
- cout << endl;
- cout << "Result: " << fibonacci(n) << endl;
- char choice;
- cout << "Введите, хотите ли продолжить работу (1 - да, 2 - нет): ";
- cin >> choice;
- if (choice == '1') {
- init();
- }
- }
- int fibonacci(int n) {
- if (!n) {
- return 1;
- } else if (n == 1) {
- return 1;
- } else {
- return fibonacci(n-2) + fibonacci(n-1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment