zoukankan      html  css  js  c++  java
  • C 语言实例

    C 语言实例 - 矩阵转换
    
    C 语言实例 C 语言实例
    矩阵转换。
    实例
    #include <stdio.h>
     
    int main()
    {
        int a[10][10], transpose[10][10], r, c, i, j;
        printf("输入矩阵的行与列: ");
        scanf("%d %d", &r, &c);
     
        // 存储矩阵的元素
        printf("
    输入矩阵元素:
    ");
        for(i=0; i<r; ++i)
            for(j=0; j<c; ++j)
            {
                printf("输入元素 a%d%d: ",i+1, j+1);
                scanf("%d", &a[i][j]);
            }
     
        // 显示矩阵 a[][] */
        printf("
    输入矩阵: 
    ");
        for(i=0; i<r; ++i)
            for(j=0; j<c; ++j)
            {
                printf("%d  ", a[i][j]);
                if (j == c-1)
                    printf("
    
    ");
            }
     
        // 转换
        for(i=0; i<r; ++i)
            for(j=0; j<c; ++j)
            {
                transpose[j][i] = a[i][j];
            }
     
        // 显示转换后的矩阵 a
        printf("
    转换后矩阵:
    ");
        for(i=0; i<c; ++i)
            for(j=0; j<r; ++j)
            {
                printf("%d  ",transpose[i][j]);
                if(j==r-1)
                    printf("
    
    ");
            }
     
        return 0;
    }
    输出结果为:
    输入矩阵的行与列: 2 3
    
    输入矩阵元素:
    输入元素 a11: 2
    输入元素 a12: 3
    输入元素 a13: 4
    输入元素 a21: 5
    输入元素 a22: 6
    输入元素 a23: 4
    
    输入矩阵: 
    2  3  4  
    
    5  6  4  
    
    
    转换后矩阵:
    2  5  
    
    3  6  
    
    4  4  
  • 相关阅读:
    python基础 条件和循环
    git基本使用(搭建Git服务器)
    面试题整理
    node nvm npm nrm 安装
    onmouse事件
    webpack
    web前端UI框架
    javascript cookie
    三大家族,offset,scroll,client
    clientTop,scrollTop,兼容
  • 原文地址:https://www.cnblogs.com/bytebee/p/8535642.html
Copyright © 2011-2022 走看看