• 矩阵转换


    include "stdafx.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #define N 10
    void Swap(int *x,int *y);
    void Transpose(int a[][N],int n);
    void InputMatrix(int a[][N],int n);
    void PrintMatrix(int a[][N],int n);
    int main()
    {
     int s[N][N],n;
     printf_s("input n:");
     scanf_s("%d",&n);
     InputMatrix(s,n);
     Transpose(s,n);
     printf_s("The transposed matrix is : ");
     PrintMatrix(s,n);
     system("pause");
     return 0;
    }
    void Swap(int *x,int *y)
    {
     int temp;
     temp = *x;
     *x = *y;
     *y = temp;
    }
    void Transpose(int a[][N],int n)
    {
     int i,j;
     for(i = 0;i < n;i++)
     {
      for(j = i;j < n;j++)
      {
       Swap(&a[i][j],&a[j][i]);
      }
     }
    }
    void InputMatrix(int a[][N],int n)
    {
     int i,j;
     printf_s("input %d*%d matrix: ",n,n);
     for(i = 0;i<n;i++)
     {
      for(j = 0;j < n; j++)
      {
       scanf_s("%d",&a[i][j],sizeof(a[i][j]));
      }
     }
    }
    void PrintMatrix(int a[][N],int n)
    {
     int i,j;
     for(i = 0;i < n;i++)
     {
      for(j = 0;i < n;j++)
      {
       printf_s("%d ",a[i][j]);
      }
      printf_s(" ");
     }
    }

  • 相关阅读:
    228. Summary Ranges
    227. Basic Calculator II
    224. Basic Calculator
    222. Count Complete Tree Nodes
    223. Rectangle Area
    221. Maximal Square
    220. Contains Duplicate III
    219. Contains Duplicate II
    217. Contains Duplicate
    Java编程思想 4th 第4章 控制执行流程
  • 原文地址:https://www.cnblogs.com/joyclub/p/4423207.html
Copyright © 2020-2023  润新知