Answer to Question #328317 in C++ for Lexi

Question #328317

Create a program that countsand displaysthe odd and even numbers among the ten(10)input values.Array Requirements:Use 3separate arraysforteninput values, evenand odd num



1
Expert's answer
2022-04-13T10:33:00-0400
#include <iostream>
#include <vector>

using namespace std;

void main()
{
	const int N = 10;
	int arr[N];
	vector<int>even;
	vector<int>odd;
	cout << "Please, enter 10 integer values: ";
	for (int i = 0; i < N; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < N; i++)
	{
		if (arr[i] % 2 == 0)
			even.push_back(arr[i]);
		else
			odd.push_back(arr[i]);
	}
	cout << "\nEven numbers: ";
	for (int i = 0; i < even.size(); i++)
	{
		cout << even[i]<<" ";
	}
	cout<< "\nOdd numbers: ";
	for (int i = 0; i < odd.size(); i++)
	{
		cout << odd[i]<<" ";
	}
}

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