-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2.1.cpp
More file actions
45 lines (40 loc) · 725 Bytes
/
2.1.cpp
File metadata and controls
45 lines (40 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
bool fibon_elem(int ,int&);
int main()
{
int pos, elem;
char ch;
bool more = true;
while (more)
{
cout << "Please enter a position:";
cin >> pos;
if (fibon_elem(pos,elem))
cout << "elemment # " << pos
<< " is " << elem << endl;
else
cout << "Sorry, Count not calculate element"
<< pos << endl;
cout << "Do you want to continie (y/n):";
cin >> ch;
if (ch != 'y' && ch!= 'Y')
more = false;
}
return 0;
}
bool fibon_elem (int pos, int& elem)
{
if (pos <=0 || pos >1024)
{ elem =0; return false; }
elem = 1;
int n_2 = 1;
int n_1 = 1;
for (int ix = 3; ix <= pos; ++ix)
{
elem = n_2 + n_1;
n_2 = n_1;
n_1 = elem;
}
return true;
}