Tuesday, 27 August 2013

Chapter 8 Solutions Problem [L][c]

Question-Write a program to obtain transpose of a 4 x 4 matrix. The 
transpose of a matrix is obtained by exchanging the elements 
of each row with the elements of the corresponding column
Solution-
A fundamental question.let's see the solution.

#include <stdio.h>
#include <stdlib.h>
#define m 3
#define n 3
int main()
{
int arr[m][m];
int i,j;
printf("Enter the elements of the matrix\n");
for(i=0;i<=m-1;i+=1)
{
for(j=0;j<=n-1;j+=1)
{
scanf("%d",&arr[i][j]);
}
}
printf("Transpose matrix is given by\n");
for(i=0;i<=m-1;i+=1)
{
for(j=0;j<=n-1;j+=1)
{
printf("%d ",arr[j][i]); /*Just Exchanging column and row in printf statement */
}
printf("\n");
}
getch();


}

No comments:

Post a Comment