Home > Back-end >  To solve the c array
To solve the c array

Time:05-06

Don't know how to get into a topic, they wrote a total of three order matrix, but still have questions, please raise a point of great god

CodePudding user response:

Hand into the function, the array note array into function will degenerate into a pointer, so let's hand in the size also

CodePudding user response:

Reference:
 # include 
#include
using namespace std;

Void sum (int * a, b, int * int * c)
{
Int m, n;
for(n=0; N<3; N++)
for(m=0; M<3; M++)
* (c + +)=* (+ +) * (b++);
}


Int main ()
{
Int I, j;
B int a [3], [3], [3], [3], c [3] [3].

Cout<& lt;" A is the third order matrix "& lt; & lt;" Please enter A [3] [3] value: "& lt; for(i=0; i<3; I++)
for(j=0; j<3; J++)
Cin> A, [I] [j].

Cout<& lt;" For the third order matrix B "& lt; & lt;" Please enter the B [3] [3] value: "& lt; for(i=0; i<3; I++)
for(j=0; j<3; J++)
Cin> B [I] [j];

[0] the sum (a, b [0], c [0]).

Cout<& lt;" Matrix A [3] [3] + B [3] [3]="& lt; for(i=0; i<3; I++)
for(j=0; j<3; J++)
Cout
return 0;
}


//A is the third order matrix please enter A [3] [3] value:
//1 2 3 4 5 6 7 8 9
Please enter//B for the third order matrix B [3] [3] value:
//1 2 3 4 5 6 7 8 9
//matrix A [3] [3] + B [3] [3]=
//2 4 6
//8 10 12
//14 16 18
//please press any key to continue...

CodePudding user response:

 
#include
using namespace std;

//generator matrix
Int * * creatInt (size_t size_t m, n)
{
Int a=new int * * * [m].//generated line m
For (size_t I=0; I & lt; m; + + I)
{
A [I]=new int [n].//per n int
}
return a;
}

//initialization matrix
Void init (int * * a, size_t m, size_t n)
{
For (size_t I=0; I & lt; m; + + I)
{
For (size_t j=0; J & lt; n; + + j)
{
A [I] [j]=rand () 99 + % 1;
}
}

}

//output matrix
Void Print (int * * a, size_t m, size_t n)
{
For (size_t I=0; I & lt; m; + + I)
{
For (size_t j=0; J & lt; n; + + j)
{
Cout & lt; }
Cout & lt; }

}


Int main ()
{
Size_t m, n;
Cin & gt;> M & gt;> n;

Int A=* * creatInt (m, n);
Int * * B=creatInt (m, n);
Int * * C=creatInt (m, n);

Srand (time (NULL));
Init (A, m, n);
Init (B, m, n);

For (size_t I=0; I & lt; m; + + I)
{
For (size_t j=0; J & lt; n; + + j)
{
C [I] [j] A [I] [j] + B=[I] [j];
}
}

Cout & lt; <"Matrix A: \ n";
Print (A, m, n);

Cout & lt; <"The matrix B: \ n \ n";
Print (B, m, n);

Cout & lt; <"Matrix C: \ n \ n";
Print (C, m, n);

return 0;
}


  • Related