Create
a
program that will count and display the odd and even numbers among the
ten(10)
input
values
using a two
dimensional array.
#include <iostream>
using namespace std;
int main() {
int arr[2][10];
int odd=0, even = 0;
int x;
for (int i=0; i<10; i++) {
cin >> x;
if (x%2 == 0) {
arr[0][even++] = x;
}
else {
arr[1][odd++] = x;
}
}
cout << "Even numbers: ";
for (int i=0; i<even; i++) {
cout << arr[0][i] << " ";
}
cout << endl << "Odd numbers: ";
for (int i=0; i<odd; i++) {
cout << arr[1][i] << " ";
}
return 0;
}
Comments
Leave a comment