Create a c++ program that counts and displays the odd and even numbers among the 10 input values.
Array: Use 3 separate arrays. First output displays the count and list of even and odd numbers. Next output says 'All numbers are even' and third says 'All numbers are odd'
#include <iostream>
using namespace std;
int main()
{
int ar[10];
int Odd=0;
int even=0;
for(int i=0;i<10;i++)
{
cout<<"Please input array["<<i+1<<"]=";
cin>>ar[i];
if(ar[i]%2==0)
even++;
else
Odd++;
}
if(Odd==10)
cout<<"All numbers are odd\n";
else if(even==10)
cout<<"All numbers are even\n";
else
{
cout<<"Numbers odd: "<<Odd<<endl;
cout<<"Numbers even: "<<even<<endl;
}
return 0;
}
Comments
Leave a comment