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

Hi, I need this simple program done with C++. I hope the guidelines are clear. Y

ID: 3840924 • Letter: H

Question

Hi,

I need this simple program done with C++. I hope the guidelines are clear. Your help is much appreciated.

Thank you

Given that nums[MAX_ ROWS][MAX _COLS] 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: nums [MAX _ROWS] [MAX_ COLS] Length (rows) Width (cols) The function should return an integer. The constants MAX _ROWS and MAX _COLS may be accessed globally by defining the following global constants: const int MAX _ROWS = 3 const int MAX_ COLS = 2; The array A is initialized by the following statement in your main(): int nums [MAX _ROWS][MAX _COLS] = {{3, 2}, {4, 5}, {2, 2}};

Explanation / Answer

#include <iostream>

using namespace std;

const int MAX_ROWS = 3;

const int MAX_COLS = 2;

int evenMatrix(int nums[MAX_ROWS][MAX_COLS], int rows, int cols)

{

int even = 0;

for(int i=0;i<rows;i++)

{

for(int j=0; j<cols; j++)

{

if(nums[i][j] % 2 == 0)

even = even + 1;

}

}

return even;

}

int main()

{

int nums[MAX_ROWS][MAX_COLS] = { {3,2},{4,5},{2,2}};

int res = evenMatrix (nums, MAX_ROWS, MAX_COLS);

cout << "Total even numbers are : " << res;

return 0;

}

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