Given that A[MAX_ROWS][MAX_COLUMNS] is a 2 dimensional array of integers write a
ID: 3783864 • Letter: G
Question
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.