Answer to Question #339497 in C++ for ryy

Question #339497

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'


1
Expert's answer
2022-05-10T16:00:36-0400





#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;
}

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