Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given that A[MAX_ROWS][MAX_COLUMNS] is a 2 dimensional array of integers write a

ID: 3783864 • Letter: G

Question


Given that A[MAX_ROWS][MAX_COLUMNS] is a 2 dimensional array of integers write a C ++ function. Even to find the total number of even elements in the array. It should have 3 input parameters array A, length and width. The function should return an integer. The constants MAX_ROWS and MAX_COLUMNS may be accessed globally by defining the following global variables. #define MAX_ROWS 3 #define MAX_COLUMNS 2 The array A is initialized by the following statement in your main(); in A[MAX_ROWS][MAX_COLUMNS] = {{3, 2}, {4, 5}, {2, 2};

Explanation / Answer

The following code will give you the required functionality:

#include<iostream>
using namespace std;

#define MAX_ROWS 3
#define MAX_COLOUMNS 2

int Even(int A[MAX_ROWS][MAX_COLOUMNS],int length, int width);

int main()
{
int A[MAX_ROWS][MAX_COLOUMNS] = {{3,2},{4,5},{2,2}};
int even_no;
even_no = Even(A, MAX_ROWS, MAX_COLOUMNS);
cout<<"No. of even values are: "<<even_no;
return 0;
}//end of main function

int Even(int A[MAX_ROWS][MAX_COLOUMNS],int length, int width)
{
int cnt = 0;
for(int i=0;i<length;i++)
{
for(int j=0; j<width; j++)
{
if(A[i][j]%2==0)
cnt++;
}
}//end of for loop
return cnt;
}//end of Even function

Paste the above code in your IDE and check the result.

Hope it helps.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote