---
title: "Transpose m×n matrix in FORTRAN"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-matrix-transpose"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-matrix-transpose
site: BCT Engineering
---

# Transpose m×n matrix in FORTRAN

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2070 Chaitra, 8 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-matrix-transpose
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

Write a FORTRAN program to read m*n matrix, transpose it and display both the matrices.

## Short answer

Read an m×n matrix. Transpose by B(j,i)=A(i,j). Display original and transposed matrices row by row using FORMAT.

## Answer

**Method.** The transpose of an m × n matrix A is an n × m matrix B with B(j,i) = A(i,j): rows become columns. Both the original and transposed matrices are printed.

```fortran
      PROGRAM TRANS
      INTEGER A(10,10), B(10,10)
      INTEGER M, N, I, J
      PRINT *, 'ENTER ROWS M AND COLUMNS N'
      READ *, M, N
      PRINT *, 'ENTER THE MATRIX'
      READ *, ((A(I,J), J = 1, N), I = 1, M)
      DO 20 I = 1, M
         DO 10 J = 1, N
            B(J,I) = A(I,J)
   10    CONTINUE
   20 CONTINUE
      PRINT *, 'ORIGINAL MATRIX'
      DO 30 I = 1, M
         WRITE(*,100) (A(I,J), J = 1, N)
   30 CONTINUE
      PRINT *, 'TRANSPOSED MATRIX'
      DO 40 J = 1, N
         WRITE(*,100) (B(J,I), I = 1, M)
   40 CONTINUE
  100 FORMAT(10I5)
      STOP
      END
```

**Sample:** M = 2, N = 3, A = [1 2 3; 4 5 6] gives the transpose [1 4; 2 5; 3 6].

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the rule for the transpose?
   A. B(i,j) = A(j,i) for the same i,j only when m = n
   B. B(j,i) = A(i,j)
   C. B(i,j) = -A(i,j)
   D. B(i,j) = A(i,j) / i
   Answer: B. Rows become columns, so B(j,i) = A(i,j). (Key point: Transpose rule)

2. If A is m x n, the order of its transpose B is?
   A. m x n
   B. n x m
   C. m x m
   D. n x n
   Answer: B. Rows and columns are exchanged, so a 2 x 3 matrix becomes 3 x 2. (Key point: Order of transpose)

3. Why does the program print B using DO 40 J = 1, N with (B(J,I), I = 1, M)?
   A. B has N rows and M columns
   B. B has M rows and N columns
   C. B is a one-dimensional array
   D. To print A twice
   Answer: A. B is n x m, so it has N rows, each printed with M elements. (Key point: Printing the transpose)

4. For A = [1 2 3; 4 5 6], what is the transpose?
   A. [1 4; 2 5; 3 6]
   B. [3 2 1; 6 5 4]
   C. [1 2 3; 4 5 6]
   D. [4 5 6; 1 2 3]
   Answer: A. The first row of A becomes the first column of B, etc. (Key point: Sample)

## Related in Computer Programming

- [Sum of two matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-sum) — Computer Programming, chapter 11
- [Add and subtract matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-add-subtract) — Computer Programming, chapter 11
- [Pass array; transpose 3×3 matrix](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-array-transpose-3x3) — Computer Programming, chapter 7
- [Sum of both diagonals of matrix](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asum-both-diagonals) — Computer Programming, chapter 7
- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Add two matrices](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Amatrix-add-two) — Computer Programming, chapter 7

## Related in other subjects

- [Transpose of a product of matrices](https://www.bctengineer.com/question.md?key=semester_3%2Fmathematics_iii%3Atranspose-of-a-product-of-matrices) — Mathematics III, chapter 1
- [Transpose of matrix using OOP](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Amatrix-transpose-oop) — Object Oriented Programming, chapter 1
- [Stiffness matrix: element matrices, member forces, BMD](https://www.bctengineer.com/question.md?key=semester_5%2Ftheory_of_structures_ii%3Astiffness-element-matrices-600kn-bmd) — Theory of Structures II, chapter 3
- [8086 ALP: display only alphabetic characters](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-alphabetic-only) — Microprocessor, chapter 3
