#include<stdio.h>
int main()
{
int mat[10][10];
int i,j,r,c;
printf("Enter number of Rows :");
scanf("%d",&r);
printf("Enter number of Cols :");
scanf("%d",&c);
printf("\nEnter matrix elements :\n");
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
printf("Enter element [%d,%d] : ",i,j);
scanf("%d",&mat[i][j]);
}
}
/*Transpose a matrix */
printf("\nTranspose Matrix is : \n");
for(i=0;i< c;i++)
{
for(j=0;j< r;j++)
{
printf("%d\t",mat[j][i]);
}
printf("\n");
}
return 0;
}
-------------------------------------------------------------
OUTPUT1:
Enter number of Rows :2
Enter number of Cols :2
Enter matrix elements :
Enter element [0,0] : 1
Enter element [0,1] : 2
Enter element [1,0] : 3
Enter element [1,1] : 4
Transpose Matrix is :
1 3
2 4
--------------------------------------------------------------
OUTPUT2:
Enter number of Rows :3
Enter number of Cols :3
Enter matrix elements :
Enter element [0,0] : 1
Enter element [0,1] : 2
Enter element [0,2] : 3
Enter element [1,0] : 4
Enter element [1,1] : 5
Enter element [1,2] : 6
Enter element [2,0] : 7
Enter element [2,1] : 8
Enter element [2,2] : 9
Transpose Matrix is :
1 4 7
2 5 8
3 6 9
int main()
{
int mat[10][10];
int i,j,r,c;
printf("Enter number of Rows :");
scanf("%d",&r);
printf("Enter number of Cols :");
scanf("%d",&c);
printf("\nEnter matrix elements :\n");
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
printf("Enter element [%d,%d] : ",i,j);
scanf("%d",&mat[i][j]);
}
}
/*Transpose a matrix */
printf("\nTranspose Matrix is : \n");
for(i=0;i< c;i++)
{
for(j=0;j< r;j++)
{
printf("%d\t",mat[j][i]);
}
printf("\n");
}
return 0;
}
-------------------------------------------------------------
OUTPUT1:
Enter number of Rows :2
Enter number of Cols :2
Enter matrix elements :
Enter element [0,0] : 1
Enter element [0,1] : 2
Enter element [1,0] : 3
Enter element [1,1] : 4
Transpose Matrix is :
1 3
2 4
--------------------------------------------------------------
OUTPUT2:
Enter number of Rows :3
Enter number of Cols :3
Enter matrix elements :
Enter element [0,0] : 1
Enter element [0,1] : 2
Enter element [0,2] : 3
Enter element [1,0] : 4
Enter element [1,1] : 5
Enter element [1,2] : 6
Enter element [2,0] : 7
Enter element [2,1] : 8
Enter element [2,2] : 9
Transpose Matrix is :
1 4 7
2 5 8
3 6 9
No comments:
Post a Comment