-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob2.cpp
More file actions
47 lines (34 loc) · 1.04 KB
/
prob2.cpp
File metadata and controls
47 lines (34 loc) · 1.04 KB
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
46
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#define MAX_VALUE 4000000
class fibo_vector
{
protected:
std::vector<unsigned int> numbers;
public:
unsigned int tally;
fibo_vector(unsigned int max)
{
numbers.push_back(1);
numbers.push_back(2);
unsigned int current = 0;
while (current <= max)
{
if (current != 0)
numbers.push_back(current);
unsigned int last = (numbers.size() - 1);
if (numbers[last] % 2 == 0)
this->tally += numbers[last];
current = numbers[last] + numbers[last - 1];
}
}
};
int main(int argc, char *argv[])
{
fibo_vector* vector = new fibo_vector(MAX_VALUE);
std::cout << "Sum of even elts in fibonacci sequence of max "
<< MAX_VALUE << " is: " << vector->tally << std::endl;
return 0;
}