
# include
using namespace std;
Void InitMatrix (int * *, int, int).
Int * * Multiply (int * *, int * *, int, int, int, int).
Void the Display (int * *);
Int main ()
{const int n=2;
Const int k=3;
Const int m=4;
Int a [n] [k], b [k] [m].
Int * * c;//please add the definition of c
InitMatrix (a, n, k);//initialization matrix a
InitMatrix (b, k, m);//initialization matrix b
C=Multiply (a, b, n, k, k, m);//calculate aXb
The Display (c);//output calculation results
return 0;
}
Void InitMatrix (int * * x, int q, int p)
{
Int I, j;
Int * * x;
X=new int * [q];
for(i=0; I[I] x=new int [p].
for(i=0; Ifor(j=0; JCin> [I] x [j];
}
Int * * Multiply (int * * a, b, int * * int n, int k, int l, int m)
{
Int I, j;
Int * * c;
C=new int * [n].
for(i=0; I[I] c=new int [m].
for(i=0; Ifor(j=0; J For (int x=0; x For (int y=0; Y [I] [j] + c=a [I] [x] + b [y] [j];
Return the c;
}
Void the Display (int * * c)
{
Cout}
CodePudding user response:
Because array and two-dimensional pointer is not equivalent relationYou can use a 2 d array pointer to "simulation", but the array itself can be understood as a kind of "type", he has the length of one dimensional attribute, and two-dimensional pointer is not
CodePudding user response:
# include
using namespace std;
Void InitMatrix (int * * *, int, int).
Int * * Multiply (int * *, int * *, int, int, int, int).
Void the Display (int * *);
Int main ()
{
Const int n=2;
Const int k=2;
Const int m=2;
//int a [n] [k], [k] [m]. B
Int a, * * * * b;
Int * * c;//please add the definition of c
InitMatrix (& amp; A, n, k);//initialization matrix a
InitMatrix (& amp; B, k, m);//initialization matrix b
C=Multiply (a, b, n, k, k, m);//calculate aXb
The Display (c);//output calculation results
return 0;
}
* * x//void InitMatrix (int, int q, int p)
* * * void InitMatrix (int x, int q, int p)
{
Int I, j;
Int * * TMP;
TMP=new int * [q];
for(i=0; ITMP [I]=new int [p].
for(i=0; Ifor(j=0; JCin> TMP [I] [j];
* x=TMP;
}
Int * * Multiply (int * * a, b, int * * int n, int k, int l, int m)
{
Int I, j;
Int * * c;
C=new int * [n].
for(i=0; I[I] c=new int [m].
for(i=0; Ifor(j=0; J For (int x=0; x For (int y=0; Y [I] [j] + c=a [I] [x] + b [y] [j];
Return the c;
}
Void the Display (int * * c)
{
Cout}
For reference, remove the compiler warnings and error;
To initialize the array, but it is not can use new inside,
CodePudding user response:
Thanks, problem solved