Answer to Question #328310 in C++ for Lexi

Question #328310

Create

a

program that will count and display the odd and even numbers among the

ten(10)

input

values

using a two

dimensional array.



1
Expert's answer
2022-04-13T16:04:59-0400
#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;
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS