Advertisement
MadCortez

Untitled

Sep 19th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int main()
  5. {
  6.     const int MIN_SIZE = 0;
  7.     const int MAX_SIZE = 47;
  8.     int n;
  9.     setlocale(LC_ALL, "Russian");
  10.     cout << "Данная программа вычисляет n-e число Фибоначчи\n";
  11.     cout << "Введите n-e число Фибоначчи в диапазоне " << MIN_SIZE + 1 << ".." << MAX_SIZE - 1 << ": \n";
  12.     bool isNotValid = true;
  13.     do {
  14.         cin >> n;
  15.         if (n > MIN_SIZE && n < MAX_SIZE)
  16.             isNotValid = false;
  17.         else
  18.             cout << "Введите число в заданном диапазоне ";
  19.     } while (isNotValid);
  20.     int fibPrev = 1;
  21.     int fibNow = 1;
  22.     for (int i = n; i > 2; i--) {
  23.         fibNow += fibPrev;
  24.         fibPrev = fibNow - fibPrev;
  25.     }
  26.     cout << n << "-e число Фибоначчи: " << fibNow;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement