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.
#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;
}
Comments
Leave a comment