Created
March 17, 2018 18:10
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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