Write a program to create 2 dynamically created, 2D Arrays (with equal
rows and columns) of user’s desired size, pass these 2 array to functions
using pointers to add Right diagonal values to 3 rd dynamically created
array and return that array to main functions using pointer.
> and return that array to main functions using pointer.
Well you don't return anything.
> (with equal rows and columns)
Why do you prompt for columns then?
Why don't you ensure that both are equal?
Compile with lots of warnings.
1 2 3 4 5
$ g++ -Wall -Wextra foo.cpp
foo.cpp: In function ‘void adddiognals(int**, int**, int, int)’:
foo.cpp:10:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if (i = j)
^
Also, a sea of variables all called ptr,x,y are not descriptive of the problem.
You basically copy/pasted the code to read both matrices, where you should have created a function.
1 2 3 4 5 6 7 8 9 10
int main ( ) {
int **matrix1, int **matrix2;
int side;
cout << "How big";
cin >> side;
matrix1 = createMatrix(side);
matrix2 = createMatrix(side);
int *diagonalSum = adddiognals(matrix1,matrix2,side);
}