-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem2.h
More file actions
37 lines (31 loc) · 703 Bytes
/
problem2.h
File metadata and controls
37 lines (31 loc) · 703 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
//
// Created by Karun Ram, Pratim Chowdhary on 4/20/22.
//
#ifndef PROJECT_EULER_PROBLEM2_H
#define PROJECT_EULER_PROBLEM2_H
#include "iostream"
using namespace std;
int fibonacci_generator(bool reset) {
static int f1 = 1;
static int f2 = 2;
int temp = f1 + f2;
f1 = f2;
f2 = temp;
if (reset) {
f1 = 1;
f2 = 2;
}
return temp;
}
void problem_2_solution(bool log) {
long max = 4000000;
int sum = 0;
for (int term = 2; term < max; term = fibonacci_generator(false)) {
if (term % 2 == 0) {
sum += term;
}
}
fibonacci_generator(true);
if (log) cout << sum << endl;
}
#endif //PROJECT_EULER_PROBLEM2_H