Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write code for the function printRowSums . It should print the sum of each row o

ID: 642347 • Letter: W

Question

Write code for the function printRowSums. It should print the sum of each row of the matrix (put a single space after each sum).
For the matrix shown here: the code is c++


You should print "15 40 "
Hints:

Going to want nested loops.

use this code

#include <iostream>
#include <climits>


using namespace std;

const int NUM_COLS = 5;

void printRowSums(const int values[][NUM_COLS], int numRows) {

//Do not modify anything on or above the line below this
//START_PROVIDED

    //YOUR_CODE

//END_PROVIDED
//Do not modify anything on or below the line above this

}

int main()
{
    int nums[2][NUM_COLS] = {{1, 2, 3, 4, 5},
                                    {11, 2, 3, 4, 5}};

    int nums2[5][NUM_COLS] = {{21, 2, 3, 4, 5},
                                     {21, 2, 3, 4, 5},
                                     {1, 12, 3, 4, 5},
                                     {2, 2, 23, 4, 5},
                                     {1, 2, 3, 24, 5}};

   
    printRowSums(nums, 2);
    cout << endl;
    printRowSums(nums2, 5);
    cout << endl;

    return 0;
}

Explanation / Answer

#include
#include


void printRowSums(int mat[20][20],int row,int col);

int main()
{

int mat[20][20];
int row,col,i,j;

cout<<"Enter the No of rows in Matrix:"< cin>>row;
cout<<"Enter the No of cols in Matrix:"< cin>>col;

cout<<"ENter the elements in Matrix:"< for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
cin>>mat[i][j];
}
}

cout<<"Display Matrix"<

for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
cout< }
cout< }
printRowSums(mat,row,col);
getch();
return 0;
}


void printRowSums(int mat[20][20],int row,int col)
{
int arr[10],pro=0;
for(int i=1;i<=row;i++)
{
pro=0;
for(int j=1;j<=col;j++)
{
pro=pro+mat[i][j];
}
arr[i]=pro;
}

for(int k=1;k<=row;k++)
{
cout< }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote