zoukankan      html  css  js  c++  java
  • C语言--矩阵置换

     1 //takePlace里的循环写错了,j循环应该是
     2 //for (j=i;j<3;j++)
     3 //你那个写的交换了2遍,又变回原来的了。*//
     4 
     5 #include <stdio.h>
     6 
     7 int Array[3][3]; 
     8 void takePlace( ) 
     9 {
    10  int i,j,t; 
    11  for(i=0;i<3;i++) 
    12   for(j=i;j<3;j++) 
    13   {
    14    t=Array[i][j];
    15    Array[i][j]=Array[j][i];
    16    Array[j][i]=t;
    17   }
    18 }
    19  
    20 int main() 
    21 {
    22  int i,j; 
    23  int n=0; 
    24  printf("please enter 9 numbers:
    "); 
    25  for(i=0;i<3;i++) 
    26   for(j=0;j<3;j++) 
    27   {
    28    scanf("%d",&Array[i][j]); 
    29    printf("%3d",Array[i][j]); 
    30    n+=1; 
    31    if(n%3==0) 
    32    printf("
    ");
    33   } 
    34  printf("Now,开始转置.......
    "); 
    35  takePlace( ); 
    36  n=0; 
    37  printf("转置后的结果为:
    "); 
    38  for(i=0;i<3;i++) 
    39   for(j=0;j<3;j++) 
    40   {
    41    printf("%3d",Array[i][j]); 
    42    n+=1; 
    43    if(n%3==0) 
    44    printf("
    "); 
    45   } 
    46 }
  • 相关阅读:
    POJ
    POJ
    操作系统
    POJ
    POJ
    codeforces Educational Round 89
    codeforces Round 647(div. 2)
    codeforces Educational Round 88
    后缀自动机简单总结
    dsu on tree 简单总结
  • 原文地址:https://www.cnblogs.com/lovebing/p/9157720.html
Copyright © 2011-2022 走看看