Home > Back-end >  Why such a program is wrong?
Why such a program is wrong?

Time:10-09

CodePudding user response:

Function: no problem, don't know how to pass arguments, is may be spread to participate it

CodePudding user response:

Support the upstairs
Wrong information array passed a
Look at the input code, check whether array element is set correctly

CodePudding user response:

N==_countoff (a [0]); So n meaningless
[a] [3] [3] list a matrix [3], if you want to use a pointer array, use int * a, [3].

CodePudding user response:

reference 1st floor CHXCHXKKK response:
function is no problem, I don't know is how to pass arguments, is likely to be spread and no

Void print (int a [], [3], int m, int n)
{
Int I, j, * p=a, [0].
Srand ((unsigned) time (NULL));
Cout & lt; <"Output square:" & lt; For (I=0; I & lt; m; I++ p++)
{
For (j=0; J & lt; n; J++ p++)
{
* p=0 + rand () % (0-9 + 1);
Cout & lt; }
Cout & lt; }
}
Void main ()
{
Int a [3] [3].
Print (a, 3, 3);
Proc1 (a, 3, 3);
}
The rest is like this

CodePudding user response:

Fun
reference 2 floor response:
support
upstairsWrong information array passed a
Look at the input code, check whether array element is set to the correct

Void print (int a [], [3], int m, int n)
{
Int I, j, * p=a, [0].
Srand ((unsigned) time (NULL));
Cout & lt; <"Output square:" & lt; For (I=0; I & lt; m; I++ p++)
{
For (j=0; J & lt; n; J++ p++)
{
* p=0 + rand () % (0-9 + 1);
Cout & lt; }
Cout & lt; }
}
Void main ()
{
Int a [3] [3].
Print (a, 3, 3);
Proc1 (a, 3, 3);
}
The rest is like this

CodePudding user response:

The
reference 3 floor GKatHere response:
n==_countoff (a [0]); So n meaningless
[a] [3] [3] list a matrix [3], if you want to use a pointer array, use int * a, [3].

About the n I'm not quite understand what you mean

CodePudding user response:

* p=0 + rand () % (0-9 + 1); Really don't understand these 0 + (0-9 + 1) is have what special significance

CodePudding user response:

 
Void print (int a [], [3], int m, int n)//a [] [3], said a [1], [3], a [2] [3], and so on, so n is 3, parameters if the wrong, will go wrong instead
{
Int I, j, * p=a, [0].
Srand ((unsigned) time (NULL));
Cout & lt; <"Output square:" & lt; For (I=0; I & lt; m; I++)//p++ don't add the
{
For (j=0; J & lt; n; J++ p++)
{
* p=0 + rand () % (0-9 + 1);
Cout & lt; }
Cout & lt; }
}

CodePudding user response:

The
reference 7 floor CHXCHXKKK response:
* p=0 + rand () % (0-9 + 1); Really don't understand these 0 + (0-9 + 1) is it have what special significance

The random number assigned to the two-dimensional array you always feel there is a problem,

CodePudding user response:

references 9 f CHXCHXKKK response:
Quote: refer to 7th floor CHXCHXKKK response:

* p=0 + rand () % (0-9 + 1); Really don't understand these 0 + (0-9 + 1) is it have what special significance

You are such a random number assigned to the two dimensional array total felling have a question,

This means you have the elements of the division between 0 to 9 digits

CodePudding user response:

references to the tenth floor sorrow brake brake response:
Quote: references 9 f CHXCHXKKK response:
Quote: refer to 7th floor CHXCHXKKK response:

* p=0 + rand () % (0-9 + 1); Really don't understand these 0 + (0-9 + 1) is it have what special significance

You are such a random number assigned to the two dimensional array total felling have a question,

This means you have elements of the division between 0 to 9 digits


Your code changes, as a reference.
 
# include & lt; Iostream>
# include & lt; Cstdlib>
# include & lt; Ctime>

using namespace std;

Void print (int (* a) [3], int m, int n)
{
Int I, j;
Srand ((unsigned) time (NULL));
Cout & lt; <"Output square:" & lt; for(i=0; I{
for(j=0; j{
* (* (a + I) + j)=rand () % 9 + 1;
Cout & lt; <* (* (a + I) + j) & lt; <"";
}
Cout & lt; }
}

Void proc (int a [], [3], int m, int n)
{
Int I, j, sum=0;
for (i=0; I{
for(j=0; j{
The sum +=* (* (a + I) + j).
}
Cout & lt; <"The first" & lt; Sum=0;
}
}

Int main ()
{
Int arr [3] [3].
Print (arr, 3, 3);
Proc (arr, 3, 3);
return 0;
}
  • Related