Answer to Question #339054 in C++ for ryy

Question #339054

Create a c++ program the counts and display the odd and even numbers among the ten input values using a two dimensional array.


First row - 10 input numbers

Second row - even numbers

Third row - odd numbers


1
Expert's answer
2022-05-09T14:54:50-0400
#include<iostream>

using namespace std;
int main()
{
   int eve = 0, odd = 0, i = 0, j = 0, k = 0;
   int arr[3][10];
   cout<<"Enter 10 Array Elements:\n";
   for(i=0; i<10; i++)
      cin>>arr[0][i];
   for(i = 0; i < 10; i++){
   		if(arr[0][i] % 2 == 0){
   			eve++;
   			arr[1][j] = arr[0][i];
   			j++;   			
		}
      	else{
      		odd++;
      		arr[2][k] = arr[0][i];
   			k++;   
		}
   }
   
   cout << "\nTotal Number of Even Numbers = " << eve;
   cout << "\nTotal Number of Odd Numbers = " << odd << endl;
   
   for (int n = 0; n < 3; n++){
   	   	if (n == 0){
   	   	    for(i = 0; i < 10; i++)
	  			cout << arr[n][i] << "  ";
			cout << endl;
		}
		if (n == 1){
   	   	    	for(j = 0; j < eve; j++)
	  				cout << arr[n][j] << "  ";
				cout << endl;
			}
		if (n == 2){
   	   	    	for(k = 0; k < odd; k++)
	  				cout << arr[n][k] << "  ";
				cout << 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