Q:

Write C Program to Find the Transpose of a given Matrix

0

Write C Program to Find the Transpose of a given Matrix

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used CodeBlocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
void main()
{
    static int array[10][10];
    int i, j, m, n;
 
    printf("Enter the order of the matrix \n");
    // Inputing elements in matrix from user
    scanf("%d %d", &m, &n);
    printf("Enter the coefiicients of the matrix\n");
    for (i = 0; i < m; ++i)
    {
        for (j = 0; j < n; ++j)
        {
            scanf("%d", &array[i][j]);
        }
    }
    //Printing the original matrix
    printf("The given matrix is \n");
    for (i = 0; i < m; ++i)
    {
        for (j = 0; j < n; ++j)
        {
            printf(" %d", array[i][j]);
        }
        printf("\n");
    }
    //Printing the transpose of matrix
    printf("Transpose of matrix is \n");
    for (j = 0; j < n; ++j)
    {
        for (i = 0; i < m; ++i)
        {
            printf(" %d", array[i][j]);
        }
        printf("\n");
    }
}

Result:

Enter the order of the matrix 

3

3

Enter the coefiicients of the matrix

1

2

3

4

5

6

7

8

9

The given matrix is 

 1 2 3

 4 5 6

 7 8 9

Transpose of matrix is 

 1 4 7

 2 5 8

 3 6 9

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C Program to Find sum of each row and column... >>
<< Write C Program to check whether two matrices are ...