Q. Write a C program to accept value of matrix and find the transpose matrix.
/*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);
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:
The output of above program would be:
good logic.......
ReplyDeleteBut where have you declared 'matB'? You might have missed out on a line. Otherwise good logic.
ReplyDelete@Diwakar Ray,
DeleteYeah, that is mistake!
Now i re-write code of above program with screen-shot of output.
hey i cant understand this
Deleteit is so tough
this program is wrong.. it shows garbage value when 2*3 matrix is taken
Delete