Question

In: Computer Science

Write a function declaration for a function that sums each row of a 2D array, where...

Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. IN C Program.

Solutions

Expert Solution

Here is the answer for your question in C Programming Language.

Kindly upvote if you find the answer helpful.

###########################################################################

CODE :

#include<stdio.h>
//Declare size of row
#define N 10

//Function prototype
void sumRows(int[][N],int);

void main(){
   //Required variables and decleration
   int m = 3,i,j;
   int array[][N] = {{1,2,3,4,5,6,7,8,9,10},
   {11,12,13,14,15,16,17,18,19,20},
                   {21,22,23,24,25,26,27,28,29,30}};

   //Prints given array                  
   printf("Given array of elements: \n");
   printf("===========================\n");
   for(i = 0;i < m;i++){      
       for(j = 0;j<N;j++){
           printf("%d ",array[i][j]);
       }
       printf("\n");
   }
   printf("===========================\n");
   //Calls method
   sumRows(array,m);
}
//Implementation of sumRows that takes array and number of rows
void sumRows(int array[][N],int M){
   //Required variables
   int sum,i,j;
   //Loops through number of rows
   for(i = 0;i < M;i++){
       //Each time sets sum to 0
       sum = 0;
       //Loops through number of columns
       for(j = 0;j<N;j++){
           //Adds each column value of a row to sum
           sum += array[i][j];
       }
       //Prints sum
       printf("\Sum of all elements in row #%d is %d\n",(i+1),sum);
   }
}

####################################################################

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code.

###########################################################################

OUTPUT :

Any doubts regarding this can be explained with pleasure :)


Related Solutions

Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. Need it in 10 minutes, please.
write a function declaration for a 2d array where each row size is 8 and the...
write a function declaration for a 2d array where each row size is 8 and the function does not return anything.
Which row has the largest sum? Write a method that takes a 2D int array and...
Which row has the largest sum? Write a method that takes a 2D int array and prints: of The index of the row that has the largest sum The sum of elements in that row java
How to print the element in the fifth row and seventh column given this array declaration...
How to print the element in the fifth row and seventh column given this array declaration in dev c: int hello[5][10];
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and...
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and returns only the odd index entries. Do this by first setting the even entries to 0, and then removing the 0 entries by using a logical array. The first line of your code should read function p = ReturnOddEntries(p) For example, if you run in the command window p = ReturnOddEntries([1.2 7.1 8.4 -42 100.1 7 -2 4 6]), then you should get p...
Write a function script DirCos.m that takes a vector (any row or column array) as the...
Write a function script DirCos.m that takes a vector (any row or column array) as the argument and returns the direction cosines for that vector. This is for a MatLab script
C++ How do you make a 2d array with a user input. For example, the row...
C++ How do you make a 2d array with a user input. For example, the row and columns of the 2d array will be the same so the program can create a square matrix.
Suppose that every row of M sums to k. Prove that M^n has constant row sums,...
Suppose that every row of M sums to k. Prove that M^n has constant row sums, and find that row sum.
Challenge 3 – Make 2D Array Write a function that takes 3 parameters and makes use...
Challenge 3 – Make 2D Array Write a function that takes 3 parameters and makes use of your prior two functions to create a 2D array filled with a default parameter. var twoD = Init2D(<width>, <height>, <fill val>); Challenge 4 – Random Integer in Range Write a function to return a random integer between a minimum value and maximum value. var ival = IntRandomRange(<min>, <max>); Challenge 5 – Random Int 2D Array Use your prior functions to provide a function...
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input #...
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input # of rows: 2 Input Row 1: 9 8 7 6 3 2 1 5 4 Input Row 2: 1 2 4 3 5 6 9 8 7 Output 1,2,3,4,5,6,7,8,9 1,2,3,4,5,6,7,8,9
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT