Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Algorithm
3.
Code
4.
Output
5.
FAQs
6.
Key Takeaways
Last Updated: Mar 27, 2024
Easy

Transpose of a Matrix using C

Introduction

Let us first understand what a matrix is. A matrix (plural: matrices) is a rectangular array or table of numbers(or symbols or expressions) arranged in rows and columns to represent a mathematical object or one of its properties. A matrix is usually denoted by a capital letter. The transpose of a matrix is found by interchanging its rows into columns or columns into rows.

You can also read about dynamic array in c and C Static Function.

Algorithm

1.Declare a 2-dimensional array and initialise it.

2.Make entries of the matrix from the user. 

3.Declare another 2-dimensional array. 

4.Interchange the rows and columns and store them in the second(transpose matrix) array. 

5.Print the transpose matrix.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Code

#include<stdio.h>
int main(){
int i=3,j=3;
int rows, columns;
int arr[3][3]={{6,1,3},{4,0,3},{3,0,5}};
for(rows = 0; rows < i; rows++){
  for(columns = 0;columns < j; columns++){
      b[columns][rows] = a[rows][columns];
  }
}

 for(rows = 0; rows < j; rows++){
   for(columns = 0; columns < i; columns++){
      printf("%d \t ", b[rows][columns]);
   }
    printf("\n");
 }
 
return 0;
}

 

Check out this problem - Matrix Median

Output

6 4 3
1 0 0
3 3 5

 

Also see, Tribonacci Series and Short int in C Programming

FAQs

  1. What is the transpose of a matrix in C?
    Transpose of a matrix is obtained by interchanging all the rows and columns of the base matrix, i.e., all the rows of the base matrix will be columns of the transpose matrix and vice versa.
  2. How can we find the transpose of a matrix using C programming language?
    A 2-dimensional array is declared and initialized, and the entries are made for the given matrix. Another 2-dimensional array is declared. The rows and columns are interchanged and are stored in the second(transpose matrix) array. Then, the transpose matrix is printed.
  3. What is matrix in C programming?
    A matrix (plural: matrices) is a rectangular array or table of numbers arranged in rows and columns to represent a mathematical object or one of its properties. In C programming we can store a matrix using a two-dimensional array.

Key Takeaways

In this blog, we learnt about the approach and the code for finding the transpose of a given matrix using C language. We hope that this blog has helped you enhance your knowledge, and if you wish to learn more, check out our  Coding Ninjas Blog site and visit our Library. Do upvote our blog to help other ninjas grow.

Also read reverse a number.

Happy Learning! 

Live masterclass