I want to sum the matrix on the third row by using a function but it didn't output anything.
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int m = 5, n = 7;
void sumrow ( int *i , int *j ){
int sum = 0;
int **a = new int *[m];
for(int j = 0 ; j < n ; j ++)
a[*i] = new int [n];
sum = sum + a[2][*j];
cout << sum << endl;
}
int main () {
srand (time(NULL));
int sum = 0;
int **a = new int *[m];
for ( int i = 0 ; i < m; i++){
a[i] = new int [n];
for( int j = 0; j < n ; j++)
a[i][j] = rand() % 10;
}
for( int i = 0; i < m ; i ++){
for(int j = 0 ; j < n ; j ++){
cout << a[i][j] << " ";
}
cout << endl;
}
int i , j;
sumrow(&i,&j);
for ( int i = 0; i < m; i ++)
delete [] a[i];
delete [] a;
}
I have a problem with the function (sumrow). how can i do it to output the sum in the third row?