- Related Questions & Answers
- C Program for Tower of Hanoi
- C++ Program for Dijkstra’s shortest path algorithm?
- C/C++ Program for nth Catalan Number?
- C Program to Multiply two Floating Point Numbers?
- C program to find the length of a string?
- C Program to Check if all digits of a number divide it
- C Program to Check if a Given String is a Palindrome?
- Write a program to Delete a Tree in C programming
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Sum of the nodes of a Singly Linked List in C Program
- Sum of first n natural numbers in C Program
- C Program for simple interest?
- Area of a n-sided regular polygon with given Radius in C Program?
- Area of a leaf inside a square in C Program?
- C Program for Area of a square inscribed in a circle which is inscribed in a hexagon?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− We are given a matrix, we need to display transpose of the matrix.

Transpose of a matrix is obtained by replacing the value present at A[i][j] by A[j][i].

Now let’s observe the concept in the implementation below−

def transpose(A,B): for i in range(M): for j in range(N): B[i][j] = A[j][i] # driver code M = N = 4 A = [ [0, 1, 1, 0], [0, 2, 0, 2], [0, 3, 0, 3], [0, 0, 4, 4]] B = A[:][:] # empty matrix transpose(A, B) print("Transformed matrix is") for i in range(N): for j in range(N): print(B[i][j], " ", end='') print()

Transformed matrix is 0 0 0 0 0 2 3 0 0 3 0 4 0 0 4 4

# function def transpose(A): for i in range(M): for j in range(i+1, N): A[i][j], A[j][i] = A[j][i], A[i][j] M = N = 4 A = [ [0, 1, 1, 0], [0, 2, 0, 2], [0, 3, 0, 3], [0, 0, 4, 4]] transpose(A) print("Transformed matrix is") for i in range(M): for j in range(N): print(A[i][j], " ", end='') print()

Transformed matrix is 0 0 0 0 0 2 3 0 0 3 0 4 0 0 4 4

In this article, we have learned how we can transpose the matrix.

Advertisements