11325 - Transpose of A Matrix   

Description

Given a matrix A (you can consider it as a 2-D array), print out transpose of A.

Note: Try to use dynamic memory management to finish this problem.

main.c

#include <stdio.h>

#include "function.h"


int main(void) {


  int **mat;

  int m, n, i;


  scanf("%d %d", &m, &n);


  mat = allocateMat(m, n);

  readInput(mat, m, n);

  printResult(mat, m, n);


  // Be sure to release acquired memory space

  for(i=0; i<m; i++)
    free(mat[i]);
  free(mat);

  return 0;

}

function.h

#ifndef FUNCTION_H

#define FUNCTION_H


int** allocateMat(int, int);

void readInput(int**, int, int);

void printResult(int**, int, int);


#endif

Input

First line has two unsigned integers, indicates A is M rows by N columns. Next M lines are the content of A, each line has N integers.

Output

N lines, each line contains M integers. Values are separated by a blank. There’s a blank and a newline at the end of each line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11325.c

Partial Judge Header

11325.h

Tags




Discuss