Answer to Question #296940 in C++ for Sheldon

Question #296940

Write a program that first reads an integer for the array size, then





reads numbers into the array, counts the even numbers and the odd numbers and





displays them.

1
Expert's answer
2022-02-12T06:58:56-0500
#include <iostream>
using namespace std;




int main(){
	int numbers[1000];
	int size;
	int evenNumbers=0;
	int oddNumbers=0;
	cout<<"Enter the size of array: ";
	cin>>size;
	for(int i=0;i<size;i++){
		cout<<"Ente the number "<<(i+1)<<": ";
		cin>>numbers[i];
	}
	for(int i=0;i<size;i++){
		if(numbers[i]%2==0){
			evenNumbers++;
		}else{
			oddNumbers++;
		}
	}


	cout<<"The even numbers: "<<evenNumbers<<"\n";
	cout<<"The odd numbers: "<<oddNumbers<<"\n";




	system("pause");
	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