Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int a, b, n = 0;
- a = 1;
- b = 1;
- cout << "The program will calculate the n-th term of the Fibonacci series.\n";
- bool IsCorrect;
- cout << "Enter the Fibonacci series member number: ";
- do
- {
- IsCorrect = false;
- cin >> n;
- if ((cin.fail()) or (n < 0) or (n == 0))
- {
- IsCorrect = true;
- cout << "Incorrect value. Enter the number: ";
- }
- cin.clear();
- while (cin.get() != '\n');
- } while (IsCorrect);
- for (int i = 2; i < n; i++)
- {
- b = a + b;
- a = b - a;
- }
- cout << b;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement