COMPILER STACK TRACE
None
PROGRAM EXECUTION STACK TRACE
None
COMPILER COMMAND LINE ARGUMENTS
-lm
INPUT OF THE TEST CASE
1 | #define NUM_ROWS 5 |
2 | |
3 | int arr [NUM_ROWS][3] |
4 | = { { -18, 5, 64 }, |
5 | { -29, 77, -87 }, |
6 | { 53, 14, 20 }, |
7 | { 128, -64, -47 }, |
8 | { 107, 87, -32 } } ; |
9 | |
10 | int sum = f ( arr, NUM_ROWS ) ; |
11 | |
12 | munit_assert ( sum == ((5) + (-29) + (77) + (-87) + (53) + (-47) + (107) + (87)) ) ; |
13 |
/* * C Program to sum odd integers in a matrix and return */ #include <stdio.h> #include <assert.h> #define NUM_ROWS 5 int f(int mat[][3], int num_rows) { int i, j; int sum = 0; for (i = 0; i < num_rows; i++) { for (j = 0; j < 3; j++) { if (mat[i][j] % 2 != 0) { sum += mat[i][j]; } } } return sum; } int main() { int arr [NUM_ROWS][3] = { { -18, 5, 64 }, { -29, 77, -87 }, { 53, 14, 20 }, { 128, -64, -47 }, { 107, 87, -32 } } ; int sum = f(arr, NUM_ROWS); //munit_assert(sum == ((5) + (-29) + (77) + (-87) + (53) + (-47) + (107) + (87))); assert(sum == ((5) + (-29) + (77) + (-87) + (53) + (-47) + (107) + (87))); return 0; } /* Program ends here */
Write a C function f such that … function f accepts, as input, … a two-dimensional array of...
Write a function that takes an array of integers as an argument and returns a value based on the sums of the even and odd numbers in the array. Let X = the sum of the odd numbers in the array and let Y = the sum of the even numbers. The function should return X – Y The signature of the function is: int f(int[ ] a) Examples if input array is return {1} 1 {1, 2} -1 {1,...
MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the longest string and largest number in arr. If there are two character arrays of same length, the function should return one of them. Assume that integers in the cell array are nonnegative.
Given an array of integer, please complete a function multiply(). The function accepts the first memory address of an array and the size of an array as parameters and returns the multiplication of all the elements. In order to get a full score, the function must use a loop to iterate through each element of an array. Pseudo code example: multiply([ 1, 2, 3], 3) → 6 multiply([1, 1, 4 ,2], 4) → 8 multiply([7, 0, 0, 7, 0, 7],...
C programming Write a function that accepts an array of integers as an input, and output the sum of all values and the multiplication of all values. e.g. Suppose that the array contained the following values: 1 2 3 -4 5. The function should calculate and output the sum of values (i.e. 1+2+3+(-4)+5=7) and the multiplication of all values (i.e. 1*2*3*-4*5=-120). Start by carefully writing the function prototype - put some thought into this. Think about the good programming habits,...
MATLAB function Write an efficient function, f(v) that takes a one-dimensional array of length N^2 for a square matrix (in a row-vectorized form) as an input and returns the trace of the matrix.
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) {
1. The following program calls the function countLarger that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n. The function countLarger should return the number of integers in the array that are greater than the value of the argument n. Update the program to include the definition of the function countLarger. #include <iostream> using namespace std; int countLarger(int[], int, int); // Function prototype int main() const int...
please help with this c++ question! Write a function that returns a dynamic array, of size n, composed of sequential odd integers starting from 1: 1,3,5,7, etc.. int* odd_array(int n) {
4. [Tests basic knowledge of recursion] Write a recursive static Java method that accepts an array arr of integers argument returns a list of all permutations of these integers. (A permutation of a sequence of integers is a re-arrangement of the integers. For example, one permutation of 1, 3, 4, 8, 2 is 3, 1, 2, 8, 4.) For this problem, you may assume that the input array contains no duplicate entries. Your method should return an ArrayList of int...
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....