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
Write a recursive method to form the sum of two positive integers a and b. Test your program by calling it from a main program t
77julia77 [94]

Answer:

see the code snippet below writing in Kotlin Language

Explanation:

fun main(args: Array<String>) {

   sumOfNumbers()

}

fun sumOfNumbers(): Int{

   var firstNum:Int

   var secondNum:Int

   println("Enter the value of first +ve Number")

   firstNum= Integer.valueOf(readLine())

   println("Enter the value of second +ve Number")

   secondNum= Integer.valueOf(readLine())

   var sum:Int= firstNum+secondNum

  println("The sum of $firstNum and $secondNum is $sum")

   return sum

}

5 0
3 years ago
4. The NIMS Management Characteristic of Chain of Command and Unity of Command means that each person: A. Continues to report di
Kipish [7]

Answer:

The answer is "Option C"

Explanation:

This system facilitates the establishment by state, Municipality, Militaristic, Provincial and local governments of a detailed, national framework for disaster response. This command structure of each person refers to only a single ICS boss because of NIMS management, and the wrong option can be defined as follows:

  • In option A, The Continuous report describes your daily details.
  • In option B, These reports are not in one ICS supervisor.
  • In option D, It can not assign different competences.
8 0
2 years ago
To format an individual sparkline, select the sparkline you want to format, and then click the Ungroup button in the Group group
vichka [17]

Answer:

The answer is "Option a"

Explanation:

A Sparkline is a small graph, which is available inside a sheet, that displays information visually. It displays the information is in the form of patterns on several values. It also uses underline to display the low and high value, use with sparklines, and certain alternatives were wrong, which can be defined as follows:

  • In option b, It is used to define the overall view of data, that's why it is wrong.
  • Option c and Option d both are wrong because, create command is used to create data, or view is used to show that data, they both don't use sparkline option.  
3 0
3 years ago
Why is removing presentation-oriented markup from one's html document considered to be a best practice?
Gelneren [198K]

Answer

Its for the purpose of  maintenance and readability

Explanation

A presentation-oriented markup web application generates interactive web pages containing various types of markup language.

Markup is a language designed for the purposes of processing definition and presentation. It specifies code for formatting, both the layout and style, within a text file. Markup describes the structure while the styling is how it looks. it uses the code to specify the formatting which are called tags.

3 0
3 years ago
Which of the following are true if you pay only the minimun amount each month towards your credit card bill? You will be charged
torisob [31]

Both A and B are true. Check out this link: https://www.nerdwallet.com/blog/credit-cards/minimum-payment-credit-card/

I hope this helps!

6 0
2 years ago
Other questions:
  • Which of the following is not a network connection LAN WAN SAN MAN
    6·1 answer
  • Which of these are examples of metadata for an audio file of a song recording?
    10·2 answers
  • Please help!! Even if you help a little I will be very thankful!
    7·1 answer
  • Some numbers are formed with closed paths. the digits 0, 4, 6 and 9 each have 1 closed path and 8 has 2. None of the other numbe
    6·1 answer
  • Were does igneous rocks cool?
    9·1 answer
  • "If a user on a laptop complains that they are unable to sign into Windows even though they are certain they are entering the co
    12·1 answer
  • If I want to add a new slide to my presentation, which option would I click on?
    5·1 answer
  • Justice wrote a program and forgot to put the steps in the correct order. Which step does she need to review?
    5·2 answers
  • How to create a network of relevant prospects?
    5·1 answer
  • Explain the history of computing device of mechanical era
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!