Home > Back-end >  [C language help] function parts: matrix transpose output a strange number
[C language help] function parts: matrix transpose output a strange number

Time:03-28

 # include & lt; stdio.h> 
#include
#include

Void PrintArray (int arr [3] [3])//function 1: print the original matrix
{
int i,j;
for(i=0; i<3 I + +)
{
for(j=0; j<3; J++)
{
Printf (" % d ", arr [I + 1] [j + 1));
}
printf("\n");
}
}
Void TransArray (int arr [3] [3]) 2://function matrix transpose
{
int i,j;
for(i=0; i<3; I++)
{
for(j=0; j<3; J++)
{
Printf (" % d ", arr [j] [I]);
}
printf("\n");
}
}
Void main ()//main function
{

Int array [3] [3]={{1, 2, 3}, {2, 3}, {three, four, five}};
Printf (" transposed front: \ n ");
PrintArray (array [3] [3]).
Printf (" after the transpose: \ n ");
TransArray (array [3] [3]).
}


The result is like this:

Trouble help have a look, thanks!

CodePudding user response:

Print function, the printf () in the arr [I + 1] [m + 1] array subscript bounds, is directly I j

CodePudding user response:

Upstairs said to, why should I + 1, j + 1

CodePudding user response:

Main function calls in the written arguments wrong,
PrintArray (array);//PrintArray (array [3] [3]).

CodePudding user response:

Above the first inside the for lack of a semicolon, impossible to compile, believed to be caused by careless operation when copying,

CodePudding user response:

reference 1st floor QZJHJXJ response:
print function, the printf () in the arr [I + 1] [m + 1] array subscript bounds, is directly I j

Or no,

CodePudding user response:

reference forever74 reply: 3/f
main function calls in the written arguments wrong,
PrintArray (array);//PrintArray (array [3] [3]).

Or no,

CodePudding user response:

reference forever74 reply: 3/f
main function calls in the written arguments wrong,
PrintArray (array);//PrintArray (array [3] [3]).

Excuse me, can, thank you
  • Related