#Write a program using two-dimensional arrays that lists the odd numbers and even numbers separately in a given 12 input values.
Sample input/ output dialogue:
enter twelve numbers
13 15 20 13 35 40 16 18 20 18 20 19
odds
13 15 13 35 19
Even
20 40 16 18 20 18 20
#include <iostream>
using namespace std;
int main() {
const int N=12;
int arr[2][N] = {0};
cout << "Enter twelve numbers" << endl;
for (int i=0; i<N; i++) {
int x ;
cin >> x;
arr[x%2][i] = x;
}
cout << "Odds" << endl;
for (int i=0; i<N; i++) {
if (arr[1][i]) {
cout << arr[1][i] << " ";
}
}
cout << endl;
cout << "Even" << endl;
for (int i=0; i<N; i++) {
if (arr[0][i]) {
cout << arr[0][i] << " ";
}
}
cout << endl;
return 0;
}
Comments
Leave a comment