lqcdsns

对一个nxn阶的矩阵进行转置,算法如下:

#include <stdio.h>
#define n 3

void MM(int a[][n])
{
    int i,j,temp;
    for(i = 0;i < n;i++)
        for(j = 0;j < i;j++)
        {
            temp = a[i][j];
            a[i][j] = a[j][i];
            a[j][i] = temp;
        }

    for(i = 0;i < n;i++)
    {
        for(j = 0;j < n;j++)
            printf("%d", a[i][j]);
        printf("\n");
    }    
}

main()
{
    
    int A[n][n] = {
        {1,2,3},
        {4,5,6},
        {7,8,9}
    };

    MM(A);

    printf("\n");
}

 

运行结果:

 

分类:

技术点:

相关文章:

  • 2021-12-29
  • 2021-12-19
  • 2021-11-19
  • 2021-11-29
  • 2021-12-01
  • 2021-11-19
猜你喜欢
  • 2021-11-29
  • 2021-05-31
  • 2021-11-19
  • 2021-11-29
  • 2021-11-19
  • 2022-12-23
相关资源
相似解决方案