Home > Back-end >  Why wrong matrix addition
Why wrong matrix addition

Time:09-22

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The File name: examination//filename
Author: NBS//Author
Version: Version 2.2.2//
Date: 2017.03.26//Date
Description: matrix addition//used in detail the main function of the program file to complete, and other modules
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include
# include
# include
# include
# include
# include
# include



using namespace std;


Int main ()
{
Int z [1000] [1000], [1000] x [1000], c [1000] [1000], v, b;
Cin> b> v;
for(int i=1; i<=b; + + I)
for(int j=1; j<=v; + + j)
{
Cin> Z [I] [j];
}
for(int i=1; i<=b; + + I)
for(int j=1; j<=v; + + j)
{
Cin> [I] x [j];
}
for(int i=1; i<=b; + + I)
for(int j=1; j<=v; + + j)
{
C [I] [j] [I] [j]=z + x [I] [j];
}
coutreturn 0;


}

CodePudding user response:

Int z [1000] [1000], [1000] x [1000], c [1000] [1000]
1000 * 1000 * 3 * sizeof (int) is approximately equal to 12 m more than the stack size is allocated on the stack for local variables (function), should be changed to a global variable, or static variables, or dynamically allocated from the heap,

coutDo you want to do? A two-dimensional array of c the last element is c [999] [999], the subscript starting from 0,
If you want to output the entire matrix, need to reload & lt;
In addition, you manually input matrix, a two-dimensional array is not defined so big,
Type b, v, I will check it whether the value of effective (less than the dimensions of the two dimensional array)

CodePudding user response:

You manually input matrix, two-dimensional array also need not defined so big,
-
Unless you use the command line file to redirect to input data,

CodePudding user response:

Good ooolinux zeal, point a praise,

CodePudding user response:

references the frog studio reply: 3/f
ooolinux good enthusiasm, point a praise,

.
Why like my avatar?
  • Related