C Program to Transpose Matrix


To transpose any matrix in C programming language, you have to first ask to the user to enter the matrix and replace row by column and column by row to transpose that matrix and display the transpose of the matrix on the output screen as shown in the following program.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int array[3][3], i, j, arrayTranspose[3][3];
    printf("Enter 3*3 Array Elements : ");
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            scanf("%d",&array[i][j]);
        }
    }
    printf(" The Orginal Matrix is :\n");
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            printf("%d ",array[i][j]);
        }
        printf("\n");
    }
    printf("Transposing Array...\n");
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            arrayTranspose[i][j]=array[j][i];
        }
    }
    printf("Transpose of the Matrix is :\n");
    for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
        {
            printf("%d ",arrayTranspose[i][j]);
        }
        printf("\n");
    }
    getch();
}

Run


 

No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...