I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
#include <iostream>
#define MAX_SIZE 100 //Maximum size of the array
using namespace std;
int main()
{
int arr[MAX_SIZE];
int i, num, evennum, oddnum;
// Reads size and elements in array
cout<<"Enter size of the array: ";
cin>>num;
cout<<"Enter "<<num<<" elements in array: ";
for(i=0; i<num; i++)
{
cin>>arr[i];
}
evennum = 0; // Assuming 0 even numbers
oddnum = 0; // Assuming 0 odd numbers
for(i=0; i<num; i++)
{
/* If the current element of array is evennumber then increment evennumber count */
if(arr[i]%2 == 0)
{
evennum++;
}
else
{
oddnum++; // increment oddnumber count
}
}
cout<<"Total even numbers: "<<evennum<<endl;
cout<<"Total odd numbers: "<<oddnum<<endl;
return 0;
}
I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
Result:
Enter size of the array: 5
Enter 5 elements in array: 10
15
20
25
30
Total even numbers: 3
Total odd numbers: 2
need an explanation for this answer? contact us directly to get an explanation for this answer