zoukankan      html  css  js  c++  java
  • 矩阵的转置

    矩阵转置:即矩阵的行列元素互换。

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <string.h>
     4 #include <math.h>
     5 //float x1,x2,disc,p,q;
     6 #define N 3
     7 
     8 int main()
     9 {
    10     int matrix(int[][N]);
    11     int i,j;
    12     int a[N][N];
    13     printf("input a %d*%d matrix:
    ",N,N);
    14     for(i=0;i<N;i++){
    15         for(j=0;j<N;j++)
    16             scanf("%d",&a[i][j]);
    17     }
    18     printf("oraginal:
    ");
    19     for(i=0;i<N;i++){
    20         for(j=0;j<N;j++)
    21             printf("%3d",a[i][j]);
    22         printf("
    ");
    23     }
    24     matrix(a);
    25     printf("convert:
    ");
    26     for(i=0;i<N;i++){
    27         for(j=0;j<N;j++)
    28             printf("%3d",a[i][j]);
    29         printf("
    ");
    30     }
    31 system("pause");
    32 return 0;
    33 }
    34 int matrix(int a[][N]){
    35     int temp;
    36     int i,j;
    37     for(i=0;i<N;i++){
    38         for(j=i+1;j<N;j++){
    39             if(i==j)
    40                 a[i][j]=a[j][i];
    41             else{
    42                 temp=a[i][j];
    43                 a[i][j]=a[j][i];
    44                 a[j][i]=temp;
    45             }
    46         }
    47     }
    48 }
  • 相关阅读:
    “访问”美术馆
    加分二叉树
    有线电视网
    二叉苹果树
    鬼子进村
    遍历问题
    最大子树和
    FBI树
    求前序遍历
    JS如何实现点击页面内任意的链接均加参数跳转?
  • 原文地址:https://www.cnblogs.com/crystalmoore/p/5924889.html
Copyright © 2011-2022 走看看