Question

C++.Write the body of a function that returns the sum of all elements in a two-dimensional...

C++.Write the body of a function that returns the sum of all elements in a two-dimensional array passed to it as an argument. Declare and initialize all needed variables.

int arraySum(const int numbers[][COLS], int rows)

{

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This question is little bit confusion based on the requirements provided. So please check below C++ program and revert back in case anything more needs to be implemented.

***** Program *****

#include <iostream>
using namespace std;
const int COLS = 2;
const int numbers[5][2] = { {0,0}, {1,2}, {2,4}, {3,6},{4,8}};

int arraySum(const int numbers[][COLS], int rows) {
int sum = 0;
for ( int i = 0; i < rows; i++ ) {
for ( int j = 0; j < COLS; j++ ) {
sum = sum + numbers[i][j];
}
}
cout << sum << endl;
}

int main()
{
arraySum(numbers,5);
return 0;
}

****** Output ******

using nanespaca std; const int COLS2: const ist nunters(s)(2)-((e,e), {1,2), {2,4),亿6),(4,8)); int sun ; for ( int j 0; j < C

Add a comment
Know the answer?
Add Answer to:
C++.Write the body of a function that returns the sum of all elements in a two-dimensional...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Complere a c++ function that returns the sum of all elements in a two-dimensional array of...

    Complere a c++ function that returns the sum of all elements in a two-dimensional array of double's: const int COLUMNS = 5; double sum(double values[][COLUMNS], int rows) {

  • Checkpoint 7.61 Write the prototype for a function named showSeatingChart that will accept the following two-dimensional...

    Checkpoint 7.61 Write the prototype for a function named showSeatingChart that will accept the following two-dimensional array as an argument. const int ROWS = 20; const int COLS = 40; string seatingChart[ROWS][COLS];

  • Please answer in C++, and Please consider ALL parts of the question, especially where it asks the...

    Please answer in C++, and Please consider ALL parts of the question, especially where it asks the user for V. So there should be a "cin >> V" somewhere. The last guy did not answer it correctly so please make sure you do! Thank You!! Question 1 Write the following two functions. The first function accepts as input a two-dimensional array of integers. It returns two results: the sum of the elements of the array and the average The second...

  • Write a program that finds (ANSWER IN C LANGUAGE!): 1. The sum of all elements at...

    Write a program that finds (ANSWER IN C LANGUAGE!): 1. The sum of all elements at even subscripts 2. The sum of all elements at odd subscripts 3. The sum of all elements You are allowed to perform this functionality within main. Main program: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include <stdio.h> int main() { /* Declare array variables */ const int NUM_VALS = 4; int userValues[NUM_VALS]; int i; // counter int even = 0; int odd = 0; int sum = 0; /* Initialize...

  • Write a C++ program using function that takes a Two Dimensional array, number of rows and...

    Write a C++ program using function that takes a Two Dimensional array, number of rows and number of columns in that array as argument, and returns another 2D-array containing binary representation of those numbers.

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given....

    ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given. Perform various matrix processing activities according to the algorithms below. Store the results into the output vector (one-dimensional array) with appropriate size. For Grade 7) Count the number of odd values (n mod 2 <> 0) for each row. For Grade 9) Calculate the sum of positive values for each column. To obtain inputs and return the results, define appropriate type C/C++ functions. Please...

  • C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional...

    C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....

  • Assignment: Write a program with each of the following methods. You can assume this program is...

    Assignment: Write a program with each of the following methods. You can assume this program is saved in a file called multiArrays.java. A sample main method and sample output is provided at the end of this section. All arrays created are of integer-type. Write a method to declare, initialize, and populate a two-dimensional array. Using the following header:                         public static int[ ][ ] declare2D(Scanner scnr) The user will indicate the size of the array. Write a method to declare,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT