Skip to content

Commit

Permalink
Create oddeven.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonny Li committed Feb 27, 2019
1 parent 1c5bd4f commit daa6f36
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 5-vectors/oddeven.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
#include <vector>

int main() {

int total_even = 0;
int product_odd = 1;

std::vector<int> vector = {2, 4, 3, 6, 1};

for (int i = 0; i < vector.size(); i++) {

if (vector[i] % 2 == 0) {

total_even = total_even + vector[i];

} else {

product_odd = product_odd * vector[i];

}

}

std::cout << "Sum of even numbers is " << total_even << "\n";
std::cout << "Product of odd numbers is " << product_odd << "\n";

return 0;

}

0 comments on commit daa6f36

Please sign in to comment.