Some projects--permutation of two-dimensional arrays

Source: Internet
Author: User

Title Description

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

Input

A 3x3 matrix

Output

The Matrix after transpose

Sample input
1 2 34 5 67 8 9
Sample output


Answer
#include <iostream>using namespace std;void zhuangzhi (int c[3][3]) {    int b[3][3],i,j;    for (i=0;i<3;i++) for        (j=0;j<3;j++)        b[j][i]=c[i][j];    for (i=0;i<3;i++) for        (j=0;j<3;j++)        c[i][j]=b[i][j];} 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;}


Gradually found that they forget some of the contents of the last semester, at the beginning only to think that the change of formal parameters will not affect the actual parameters, so in the formal parameters there are various pointers, references, and finally to take the address, all error. There are many ways to know that the two-dimensional function itself is a pointer, the change of the parameters can change the actual parameters, although do not know why c=b did not change .... Just give yourself a warning, remember that there is time to review the previous content

Some projects--permutation of two-dimensional arrays

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.