Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Andrew Dahl
/
Project Euler
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c18027f2
authored
Nov 15, 2011
by
Andrew Dahl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem 2 Solved
parent
eca7db7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
0 deletions
2/README
2/main.cpp
2/README
0 → 100644
View file @
c18027f2
Question:
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
Answer: 4613732
2/main.cpp
0 → 100644
View file @
c18027f2
#include <iostream>
using
namespace
std
;
int
main
()
{
int
sum
=
2
;
int
term1
=
1
;
int
term2
=
2
;
int
term_tmp
=
0
;
while
(
term2
<=
4000000
)
{
term_tmp
=
term2
;
term2
+=
term1
;
term1
=
term_tmp
;
if
(
term2
%
2
==
0
)
sum
+=
term2
;
}
cout
<<
sum
;
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment