#include <stdio.h>
#include <stdlib.h>
void main()
{
    int row, col;
    scanf("%d %d", &row, &col);
    int *matrix = malloc(col * row * sizeof(int));
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            scanf("%d", (matrix + i * col + j));
        }
    }
    for (int i = 0; i < col; i++)
    {
        for (int j = 0; j < row; j++)
        {
            printf("%d ", *(matrix + j * col + i));
        }
        printf("\n");
    }
}The transpose of a matrix is just a flipped version of 
the original matrix. We can transpose a matrix by switching 
its rows with its columns. The original rows become the new columns
and the original columns become the new rows.
We denote the transpose of matrix A by AT. 

For example:
	1 2 3                      1 4 7
A = 4 5 6       then      AT = 2 5 8
    7 8 9                      3 6 9
    
Similarly if 

B = 1 2 3       then      BT = 1 4
    4 5 6                      2 5 
                               3 6// Transpose a matrix
fn matrix_transpose(m: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
    let mut t = vec![Vec::with_capacity(m.len()); m[0].len()];
    for r in m {
        for i in 0..r.len() {
            t[i].push(r[i]);
        }
    }
    t
}

fn main() {
    let m = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]];
    println!("Matrix:\n{:?}", m);
    let t = matrix_transpose(m);
    println!("Transpose:\n{:?}", t);
}public class Solution 
{
    public int[][] Transpose(int[][] matrix) 
    {
        var trans = GenerateArray(matrix[0].Length,matrix.Length,0);
        
        for(var i=0; i<matrix.Length;i++)
        {
            for(var j=0; j<matrix[0].Length;j++)
            {
                trans[j][i] = matrix[i][j];
            }
        }
        return trans;
    }
    public static T[][] GenerateArray<T>(int row, int Col,T value)
    {
        var arr = new T[row][];

        for (int i = 0; i < row; i++)
        {
            arr[i] = new T[Col];
            for (int j = 0; j < Col; j++)
            {
                arr[i][j] = value;
            }
        }
        return arr;
    }
}function transposeMatrix(matrix) {
  if (matrix.length === 0 || matrix[0].length === 0) {
    return [];
  }

  const transposed = [];

  for (let column = 0; column < matrix[0].length; column++) {
    const newRow = [];

    for (let row = 0; row < matrix.length; row++) {
      newRow.push(matrix[row][column]);
    }

    transposed.push(newRow);
  }

  return [transposed[0]].concat(transposeMatrix(transposed.slice(1)));
}

// Example usage
const matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
const transposedMatrix = transposeMatrix(matrix);
console.log(transposedMatrix);function transposeMatrix(matrix) {
  const transposed = matrix.reduce((result, row) => {
    row.forEach((value, column) => {
      if (!result[column]) {
        result[column] = [];
      }
      result[column].push(value);
    });
    return result;
  }, []);
  
  return transposed;
}

// Example usage
const matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
const transposedMatrix = transposeMatrix(matrix);
console.log(transposedMatrix);package com.company.Array;
public class MatrixTransponse {

    public static void main (String[] args) {
        int[][] matrix = {
                {1,2,3},
                {4,5,6},
                {7,8,9}
        };

        print(matrix);

        int row = matrix.length;
        int columns = matrix[0].length;

        int [][] mat = new int[columns][row];


        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                mat[j][i] = matrix[i][j];
            }
        }
        print(mat);
    }

    public static void print(int[][] matrix){
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                System.out.print(matrix[i][j] + "\t");
            }
            System.out.println();
        }
        System.out.println("\n");
    }

}
import java.util.*;
public class MatrixTranspose {
    public static void main(String[] args) {
        Scanner Input = new Scanner (System.in);
        System.out.println("Enter number of rows");
        int row = Input.nextInt();

        System.out.println("Enter number of columns");
        int column = Input.nextInt();

        int [][] Matrix = new int [row][column];
        System.out.println("Enter "+(row*column)+" values:");
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                Matrix[i][j]= Input.nextInt();
            }
        }
        System.out.println("Before");
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                System.out.print(Matrix[i][j]+ "\t");
            }
            System.out.println("");
        }

        System.out.println("After");
        for (int i = 0; i < column; i++) {
            for (int j = 0; j < row; j++) {
                System.out.print(Matrix[j][i]+ "\t");
            }
            System.out.println("");
        }
    }
}

C相关代码片段

openGL create shape

script to check program running and restart

printf("")

Rewind to a commit Git

mouse click for colab

how to remove newline in the end of fgets string

fit text to conatiner flutter

gorm string array

js observe url change

clock skew detected makefile

time() function in c

worst fit code in c

first fit code in c

roem evaluation pyspark

calculator c

safet algorith im c

c copy char*

jfug function

soil moisture sensor interfacing with ESP32

flutter sidebar menu example

access images in c panel htaccess file

c include header file in the folder aboce

c include libray

gcc name output file

C data link escape char

How to type DLE in C

vscode Ctrl+d undo

C[strtol] func

pointer c++

power in c

sort three numbers

strip in c

c time duration

overleaf itemize a b c

route groups

itoa c code

queue in c

'wsgirequest' object has no attribute 'get'

c copy file

how to print array data in html using javascript

hello world program in c

how to compare a variable with a string in c

c print array

c rand range

exponents without pow c

how to reversed number in c

c random number with range

pthread mutex destroy while lock

pthread init mutex twice

insert c or p

woocommerce align add to cart buttons

vscode fold all code when open file

commit github non funziona

makefile both c and c++

scanf with space

c macro variable arguments

c printf format

check if prime c

read file line by line c

c use define in string

pattern program in c

Write the code in C to implement selection sort

c program of Goldbach conjecture

otput only one decimal point in c

trim string c

tokenize string c

firebase message in app doesn't work

implementing stack using linked list

esercizi semplici con le funzioni in c

array to linked list in c

sorted array to bst implementation in c

doubly linked list insertion in the middle

arch distro

distance vector routing algorithm

implement typedef with arrays

c exit vs _exit

explain in simple with c code

convert matrix to lower triangular matrix

Addition and subtraction of matrix

Transpose of a matrix