Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // msvc++
- // paulogp
- #include <iostream> // cout...
- #include <Windows.h> // Sleep
- using namespace std;
- unsigned fibonacci (unsigned the_n);
- unsigned fibonacci (unsigned the_n)
- {
- unsigned the_sum = 0;
- if (the_n > 0)
- {
- for (unsigned i = 0, f0 = 0, f1 = 1; i < (the_n - 1); ++i)
- {
- the_sum = f0 + f1;
- f0 = f1;
- f1 = the_sum;
- }}
- if (the_n > 1)
- return the_sum;
- else
- return the_n;
- }
- int main()
- {
- unsigned the_n;
- cout << "number: ";
- cin >> the_n;
- cout << "f(" << the_n << "): " << fibonacci (the_n) << endl;
- Sleep (5000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement