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) {
code:
#include<bits/stdc++.h>
using namespace std;
const int COLUMNS = 5; //declaring global variable.
double sum(double values[][COLUMNS], int rows) //function to find
the sum of all values in array.
{
double total=0; //declaring variable to sum the all values.
for(int i=0; i<rows; i++) //to read each row.
{
for(int j=0; j<COLUMNS; j++) //to read each columns.
{
total += values[i][j]; //adding each element to total.
}
}
return total; //return sum of all elements to main function.
}
int main()
{
int rows;
cout << "Enter number of rows: "; //prompting to number of
rows.
cin >> rows; //reading number of rows.
double values[rows][COLUMNS]; //declaring array.
cout << "Enter values of array: " << endl;
//prompting to enter array values.
for(int i=0; i<rows; i++)
{
for(int j=0; j<COLUMNS; j++)
{
cin >> values[i][j]; //reading the array values.
}
}
double Total = sum(values, rows); //calling the function to get
the sum of all elements in array.
cout << "Sum of all elements in a two dimensional array: "
<< Total << endl; //printing the sum of array.
return 0;
}
image of code:
output:
Note: if you have any questions or queries comment below. Thank you.
Complere a c++ function that returns the sum of all elements in a two-dimensional array of...
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) { }
c++ 48. values is a two-dimensional array of floats with 10 rows and 20 columns. Write code that sums all the elements in the array and stores the sum in the variable total 48. values is a two-dimensional array of floats with 10 rows and 20 columns. Write code that sums all the elements in the array and stores the sum in the variable total
Write a C function f such that … function f accepts, as input, … a two-dimensional array of integers in which each row has three columns the number of rows in the array function f returns the sum of the odd integers in the given array of integers and returns zero if there are no odd integers in the array COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None COMPILER COMMAND LINE ARGUMENTS -lm INPUT OF THE TEST CASE 1 #define NUM_ROWS 5...
(10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first row is initialized to 6, 8, 12, 9; the second row is initialized to 10, 13, 6, 16; and the third row is initialized to 27, 5, 10, 20. (10 pts) Consider the following declarations, and see p.566: enum brands = { GM, FORD, TOYOTA, BMW, KIA }; const int N_BRANDS = 5; const int COLOR_TYPES = 6; double...
Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...
Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4 columns. Call the following functions from function main. Call a function createArray to seed the random number generator and to fill the two-dimensional array with random integers between -20 and +20. Parameters for this function should be the array and the number of rows and columns). Call a function signs to count the number of positive values, number of negative values and number of...
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...
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 java code that Declares and initialize a two-dimensional int array named grades. It should have 10 rows and 6 columns where it stores the values and then calculates the average of all the elements in the grades array that you have declared
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....