Problem J: Write a function that allows a given two-dimensional array (3x3) to transpose, that is, the row-and-column interchange __ function

Source: Internet
Author: User

Only those who are filled with sunshine in their hearts will not despair, so even if the environment is very poor, our hearts still depend.

Description
Write a function to transpose a given two-dimensional array (3x3), that is, a row and column interchange.

Input
A 3x3 matrix.

Output
The Matrix after the transpose

Sample Input
1 2 3
4 5 6
7 8 9

Sample Output
1 4 7
2 5 8
3 6 9

HINT

The main function is given as follows, and the following main functions are not required for submission

/* C code * *

int main ()

{

int a[3][3];

int i,j;

for (i=0; i<3; i++)

For (j=0 j<3; j + +)

   scanf ("%d", &a[i][j]);

Zhuangzhi (a);

for (i=0; i<3; i++)

{

For (j=0 j<3; j + +)

    printf ("%d", a[i][j]);

 printf ("\ n");

}

return 0;

}

/* C + + code * *

int main ()

{

int a[3][3];

int i,j;

for (i=0; i<3; i++)

For (j=0 j<3; j + +)

   cin>>a[i][j];

Zhuangzhi (a);

for (i=0; i<3; i++)

{

For (j=0 j<3; j + +)

  cout<<a[i][j]<< "";

cout<<endl;

}

return 0;

}

 #include <stdio.h> void Zhuangzhi (int a1[3][3]) {int i,j,t; 
            For (i=0, i<3; i++) for (j=i; j<3; j + +)//double loops to reverse the array {t=a1[j][i]; 
            A1[J][I]=A1[I][J]; 
        a1[i][j]=t; 
    int main () {int a[3][3]; 
    int i,j; 

    For (i=0 i<3; i++) for (j=0; j<3; j + +) scanf ("%d", &a[i][j]); 
    Zhuangzhi (a); 
        For (i=0 i<3; i++) {for (j=0; j<3; j + +) printf ("%d", a[i][j]); 
    printf ("\ n"); 
return 0; } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.