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
How to save a file for the first time?​
White raven [17]

by typing ctrl+ s on keyboard

7 0
2 years ago
Read 2 more answers
Which of the following is the MOST important consideration when planning your budget?
Sladkaya [172]
C.budget for fixed expenses before flexiable expenses 

3 0
3 years ago
Read 2 more answers
an organization that maintains a gateway to the Internet and rents access to customers on a per-use of subscription basis\ and W
shtirl [24]
1. An organisation that maintains a gateway to the internet and rent access to customers on a per use of subscription basis is called INTERNET SERVICE PROVIDER [ISP]. Internet service providers are of various forms, it can be commercially or privately owned, it can also be owned by a community. The internet access provided by ISP can be inform of cable, DSL or dial up. ISP provide other services such as website building and virtual hosting.
2. Internet protocol [IP] refers to a set of rules that guide the format of data sent over the internet, it is the method by which data is sent over the internet from one computer to another computer. Each computer that is linked to the internet has a unique IP address by which it is identified and distinguished from all other computers on the internet.
8 0
2 years ago
The 16 broad career options developed by the US department of education are called
In-s [12.5K]
The answer is career clusters. 
6 0
3 years ago
SOMEBODY HELP ME ASAP PLEASE AND THANK YOU
Paha777 [63]

Answer:

Isnt there another thing that is supposed to be there like some website

Explanation:

7 0
2 years ago
Read 2 more answers
Other questions:
  • The exercise instructions here are LONG -- please read them all carefully. If you see an internal scrollbar to the right of thes
    8·1 answer
  • Which two keys on the keyboard allow an access user to move the insertion point to the next field to the right in datasheet view
    11·1 answer
  • Why is it important to not get distracted while driving?
    13·2 answers
  • A hockey stick hits a puck on the ice. identify an action-reaction pair in this situation.
    10·1 answer
  • when files on storage are scattered throughout different disks or different parts of a disk, what is it called
    10·1 answer
  • Por favor definir que es un pseudocódigo y que es un diagrama de flujo.
    13·2 answers
  • Explain the concept of “survival of the fittest”
    15·1 answer
  • What would give Lucy, an entry-level candidate, an edge over others while she seeks a programmer’s position? Lucy, an entry-leve
    11·1 answer
  • Consider the LIBRARY relational database schema description provided below which is used to keep track of books, borrowers, and
    9·1 answer
  • List one unprofessional AND one professional example of internet/social media
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!