184k views
4 votes
Given that arrayIntValues [MAX_ROWS][MAX_COLUMNS] is a 2 dimensional array of positive integers, write a C++ function howManyEven to find the total number of even elements in the array. It should have input parameter array arrayIntValues. The function should return an integer.

User Renate
by
6.3k points

1 Answer

0 votes

Answer:

Follows are the method definition to this question:

int even(int A[MAX_ROWS][MAX_COLUMNS], int length,int width)//defining a method even,that accept 2D array and two integer variables

{

int E_num = 0;//defining an integer variable E_num that holds a vlue 0

for (int i = 0; i < length; ++i)//declare for loop for row count

{

for (int j = 0; j < width; ++j)//declare for loop for column count

{

if(A[i][j]%2 == 0 )//use if block that check even number in array

{

E_num++;//incrementing the value of E_num

}

}

}

return E_num;//return E_num value

}

Step-by-step explanation:

In the above code, a method "even" is defined, which accepts a 2D array "A" and two integers " length and width" in its parameter.

Inside the method, an integer variable "E_num" is defined that uses two for loop and an if block for the count the even numbers which are available on the 2D array.

please find the attahced file for method ouput.

Given that arrayIntValues [MAX_ROWS][MAX_COLUMNS] is a 2 dimensional array of positive-example-1
User Arogachev
by
5.8k points