8000 Added sum_even example · estimand/intro-to-cpp@7c3e749 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c3e749

Browse files
committed
Added sum_even example
1 parent f6d6579 commit 7c3e749

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
const int n = 10;
8+
int x[n] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34};
9+
10+
int result = 0;
11+
for (int i = 0; i < n; i++)
12+
{
13+
if (x[i] % 2 == 0)
14+
{
15+
result += x[i];
16+
}
17+
}
18+
19+
cout << result << endl;
20+
21+
return 0;
22+
}
23+
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
set(CMAKE_CXX_STANDARD 14)
22

3-
add_executable(01_hello_world 01_hello_world.cpp)
3+
add_executable(01_sum_even 01_sum_even.cpp)
4+
5+
add_executable(02_hello_world 02_hello_world.cpp)
46

0 commit comments

Comments
 (0)
0