The title description writes a function that enables a given two-dimensional array (3x3) to transpose, that is, the row and column interchange. Enter a 3x3 matrix output to transpose matrices sample input
1 2 34 5 67 8 9
Sample output
1#include <stdio.h>2 3 4 voidConvertinta[][3],intRowintCol//two-dimensional array when making formal parameters, the second must be written5 {6 intI, J, temp;7 for(i =0; i < row; i + +)8 {9 for(j = i; J < Col; J + +)Ten { One //Exchange A if(I! =j) - { -temp =A[i][j]; theA[I][J] =A[j][i]; -A[j][i] =temp; - } - } + } - } + A intMainintargcChar Const*argv[]) at { - - //Write a function that enables a given two-dimensional array (3x3) transpose, that is, the row and column interchange - //input - inta[3][3], I, J; - for(i =0; I <3; i++) in { - for(j =0; J <3; J + +) to { +scanf"%d", &a[i][j]); - } the } * $Convert (A,3,3);Panax Notoginseng - //Output the for(i =0; I <3; i++) + { A for(j =0; J <3; J + +) the { + if(J = =0) -printf"%d", A[i][j]); $ Else $printf"%d", A[i][j]); - } -printf"\ n");//Output Enter the } - return 0;Wuyi}
Description
1, in the case of a two-dimensional array of parameters, can not use a[][], form. Should use a[][2] form
2. At the time of printing the result. Each row cannot have extra spaces.
1030:c Language Programming Tutorial (third Edition) after class exercise 8.4