Question #318389

#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

Expert's answer

#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS