1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
shepuryov [24]
3 years ago
15

Given that arrayIntValues [MAX_ROWS][MAX_COLUMNS] is a 2 dimensional array of positive integers, write a C++ function Even to fi

nd the total number of even elements in the array.
It should have input parameter array arrayIntValues.
A[length][width]
Length
Width

The function should return an integer. Also create a C++ subroutine called printArray with the input parameter array.

Computers and Technology
1 answer:
bixtya [17]3 years ago
3 0

Answer:

Here is the C++ program:

#include <iostream>  //to use input output functions

using namespace std;   // to identify objects like cin cout

const int MAX_ROWS=3;  //sets the maximum number of rows to 3

const int MAX_COLUMNS=2;  //sets the maximum number of columns to 2

//function prototypes

void printArray(const int array[MAX_ROWS][MAX_COLUMNS]);  

void Even(const int arrayIntValues[MAX_ROWS][MAX_COLUMNS]);

int main(){  //start of main method

    int arrayIntValues[MAX_ROWS][MAX_COLUMNS];   //declares a 2D array of integers

    cout<<"Enter elements of 2D array: ";  //prompts user to enter integers in a 2D array

    for(int i=0;i<MAX_ROWS;i++)  {  //outer loop to iterate through rows

               for(int j=0;j<MAX_COLUMNS;j++) //inner loop to iterate through columns

               cin>>arrayIntValues[i][j];  }   //reads and stores integers in 2D array

Even(arrayIntValues);  //calls Even method by passing arrayIntValues

printArray(arrayIntValues); }   //calls printArray method by passing arrayIntValues

void Even(const int arrayIntValues[MAX_ROWS][MAX_COLUMNS]){  //method that takes an array as parameter and finds the total number of even elements in the array

    int count = 0;  //counts the number of even numbers in array

       for(int row=0;row<MAX_ROWS;row++){  //outer loop iterates through rows of the array

               for(int col=0;col<MAX_COLUMNS;col++){  //inner loop iterates through columns of the array

               if(arrayIntValues[row][col]%2==0 && arrayIntValues[row][col]>=0)  //if the element at specified index of 2D array is an even number i.e. completely divisible by 2 and that element is positive

                               count++;   }        }  //adds 1 to the count variable each time an even positive integer appears in the array

       cout<<"total number of even elements in the array: "<<count<<endl; }   //displays the number of even element in arrayIntValues

void printArray(const int array[MAX_ROWS][MAX_COLUMNS]){  //method that takes an array as parameter and displays the even numbers in that array

       for(int row=0;row<MAX_ROWS;row++){  //outer loop iterates through rows of the array

               for(int col=0;col<MAX_COLUMNS;col++){  //inner loop iterates through columns of the array

                       if(array[row][col]%2==0 && array[row][col]>=0)  //if the element at specified index of 2D array is an even number i.e. completely divisible by 2 and that element is positive

                               cout<<array[row][col]<<endl;  //displays the even element of the array

                        else  //if element is not even

                        continue;                 }         }       }  //continues the loop to look for even elements

Explanation:

The program first prompts the user to enter elements in 2D array. It then calls Even method which iterates through the rows and columns of the array to look for the positive even numbers (elements) in array . Whenever a positive even number is encountered in the array, the count variable is incremented to 1. At the end the method returns an integer which is the total number of even elements in the array. Then the program calls printArray method which iterates through the rows and columns of the array to look for the positive even numbers (elements) in array . Whenever a positive even number is encountered in the array, that element is displayed on the output screen. The screenshot of the output is attached.    

You might be interested in
Information to develop a project network is collected from the.
Kryger [21]

Information to develop a project network is collected from the work breakdown structure

<h3>Work breakdown structure </h3>

Work breakdown structure (WBS)  is a structure showing the steps needed to be taken so as to complete a project.

WBS is presented in visual format and it is usually arranged based on hierarchy.

Information to develop a project network is collected from the work breakdown structure

Find out more on Work breakdown structure at: brainly.com/question/6197566

7 0
2 years ago
What is the duty of business to contribute to the well-being of society
NikAS [45]

Answer:

To be able to explain what’s wrong and what needs to be done

Explanation:

So if your looking at a worksheet and the costumer needs help they are gonna ask you about it so your gonna need to be able to explain what’s going on and what needs to be/get done

5 0
3 years ago
Anyone play Ps4 and wanna run up some warzone or Gta? Im M 16 so dont be a creep... :) ill mark brainliest if you drop gamertag
Nikitich [7]

Answer:

Xbox/ PC game here

Explanation:

4 0
3 years ago
Read 2 more answers
What is the definition of posture<br>​
Vinvika [58]

Answer:

The posture is how someone sits at his or her computer.

Hope this helps ;-))

6 0
3 years ago
Which statement is most likely to be true about a computer network?
emmasim [6.3K]

<em>Which statement is most likely to be true about a computer network?</em>

<em>A network can have several client computers and only one server.</em>

4 0
2 years ago
Read 2 more answers
Other questions:
  • what notation system supports presenting the largest numbers using fewest digits; Binary, decimal or hexadecimal?
    11·1 answer
  • For demultiplexing a UDP socket is identified by:_____.
    15·1 answer
  • In Windows, which menu allows you to view file characteristics?
    14·1 answer
  • You are the IT Administrator for a small corporate network. Until now, the network has consisted only of workstations accessing
    6·1 answer
  • Which are benefits of group discussions? Check all that apply. Learning becomes more interesting. Students engage in learning. L
    12·2 answers
  • What are some best practices for file management
    8·1 answer
  • What is a functional organisation? and how it functions​?
    12·1 answer
  • Computer is a major source of informarion why​
    8·1 answer
  • Which of these is NOT an input device?
    14·1 answer
  • Checking for and correcting errors may need to be done numerous during which of the following phases of the software development
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!