Skip to content

Instantly share code, notes, and snippets.

@mohnoor94
Created March 17, 2018 18:10
Show Gist options
  • Select an option

  • Save mohnoor94/432879444595b73441ce84a08426d2cb to your computer and use it in GitHub Desktop.

Select an option

Save mohnoor94/432879444595b73441ce84a08426d2cb to your computer and use it in GitHub Desktop.
Write a C++ program that reads a set of integers then finds and prints the sum of even and odd integers.
#include <iostream>
using namespace std;
int main () {
int n, x, oddSum = 0, evenSum = 0;
cout << "Enter the number of values: ";
cin >> n;
cout << "Enter your values:" << endl;
for (int i = 0; i < n; i++) {
cin >> x;
if (x % 2 == 0)
evenSum += x;
else
oddSum += x;
}
cout << "Sum of Even Numbers: " << evenSum << endl;
cout << "Sum of Odd Numbers: " << oddSum << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment