Monday, January 9, 2012

Transpose of matrix


Q. Write a C program to accept value of matrix and find the transpose matrix.

Ans.

/*program of transpose of matrix*/
#include<stdio.h>
#include<conio.h>
#define MAX 3
void input_mat(int [MAX][MAX], int, int);
void show_mat(int [MAX][MAX], int, int);
void trns_mat(int [MAX][MAX],int [MAX][MAX],int,int);
int main()
{
 int x[MAX][MAX],z[MAX][MAX];
 int row,col;
 printf("Enter no. of rows and columns : ");
 scanf("%d%d",&row, &col);
 printf("Enter values of %d X %d matrix :\n",row,col);
 input_mat(x,row,col);
 printf("\nYour entered matrix is : \n");
 show_mat(x,row,col);
 trns_mat(x,z,row,col);
 printf("\nTranspose of entered matrix is :\n");
 show_mat(z,row,col);
 return 0;
}

void input_mat(int matA[MAX][MAX], int r, int c)
{
  int i,j;
  for(i=0; i<r; i++)
  {
    for(j=0;j<c; j++)
       scanf("%d",&matA[i][j]);
  }
}


void trns_mat(int matA[MAX][MAX],int matT[MAX][MAX],int r,int c)
{
  int i,j;
  for(i=0; i<r; i++)
  {
    for(j=0;j<c; j++)
       matT[j][i] matA[i][j];
  }
}


void show_mat(int mat[MAX][MAX], int r, int c)
{
  int i,j;
  for(i=0; i<r; i++)
  {
    for(j=0;j<c; j++)
       printf(" %d",mat[i][j]);
    printf("\n");
  }
}


The output of above program would be:

Output of Transpose of matrix C program
Figure: Screen shot for transpose of matrix C program


You might also like:
  1. Difference of two matrix C program
  2. Product of matrix C program
  3. Sum of diagonal elements C program
  4. Sum of two matrix C program

No comments:

Post a Comment