C Program to Find Transpose of a Matrix (Matrix का Transpose ज्ञात करने का C प्रोग्राम)

The transpose of a matrix is obtained by interchanging its rows and columns. In the transpose matrix, rows become columns and columns become rows.

किसी Matrix की Rows को Columns में और Columns को Rows में बदलने पर उसका Transpose प्राप्त होता है। इस प्रोग्राम में हम एक 2×2 Matrix का Transpose ज्ञात करेंगे।

C Program

#include <stdio.h>
#define R 2
#define C 2
int main()
{
int a[R][C], b[C][R];
int i, j;
printf("Enter elements of Matrix A:\n");
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
printf("Enter A[%d][%d] = ", i, j);
scanf("%d", &a[i][j]);
}
}
printf("\nMatrix A is:\n");
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
printf("%d\t", a[i][j]);
}
printf("\n");
}
/* Finding transpose of Matrix A */
for (i = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
b[j][i] = a[i][j];
}
}
printf("\nTranspose of Matrix A is:\n");
for (i = 0; i < C; i++)
{
for (j = 0; j < R; j++)
{
printf("%d\t", b[i][j]);
}
printf("\n");
}
return 0;
}

Output (आउटपुट)

Enter elements of Matrix A:
Enter A[0][0] = 1
Enter A[0][1] = 2
Enter A[1][0] = 3
Enter A[1][1] = 4
Matrix A is:
1 2
3 4
Transpose of Matrix A is:
1 3
2 4

Explanation (व्याख्या)

The program uses nested for loops to read and display the matrix. To find the transpose, it interchanges the row and column indices.

  • a[R][C] stores the original matrix.

  • b[C][R] stores the transpose matrix.

  • b[j][i] = a[i][j]; assigns each element to its transposed position.

This program demonstrates how to find the transpose of a matrix using a two-dimensional array in C.

Transpose ज्ञात करने के लिए Matrix के प्रत्येक तत्व के Row और Column के स्थान को बदल दिया जाता है। उदाहरण के लिए, a[0][1] का तत्व Transpose Matrix में b[1][0] पर रखा जाता है। यह प्रोग्राम C भाषा में 2D Array की सहायता से Matrix का Transpose ज्ञात करना सिखाता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025