Saturday, June 18, 2016

C Program Code: Transpose Matrix

C Program Code 



#include<stdio.h>
int main()
{
    int matrix[3][3], transposeMatrix[3][3];
    int i, j;
    // Input Matrix
    printf("Enter matrix order 3x3 \n");
    for (i = 0; i < 3; i++)
    {
        printf("Enter Elements of %d row \n", i);
        for (j = 0; j < 3; j++)
        {
            scanf("%d", &matrix[i][j]);
        }
    }
    // Find Transpose Matrix
    for (i = 0; i < 3; i++)
    {
        for (j = 0; j < 3; j++)
        {
            transposeMatrix[i][j] = matrix[j][i];
        }
    }
    // Display Original Matrix
    printf("Original Matrix \n");
    for (i = 0; i < 3; i++)
    {
        for (j = 0; j < 3; j++)
        {
            printf("%d  ", matrix[i][j]);
        }
        printf("\n");
    }
    // Display Transpose Matrix
    printf("Transpose Matrix \n");
    for (i = 0; i < 3; i++)
    {
        for (j = 0; j < 3; j++)
        {
            printf("%d  ", transposeMatrix[i][j]);
        }
        printf("\n");
    }
    printf("Press enter to continue... \n");
    fflush(stdin);
    getchar();
    return 0;
}


Find Transpose Matrix in C Output Screenshot