WAP to find the transpose of a matrix

Write a program find to the transpose of a matrix

#include<stdio.h>

int main() {
	int a[5][5],b[5][5],row,column,n,m,i,j;

	printf("Enter the size of the 1st matrix.\n");
	scanf("%d%d",&m,&n);

	printf("Enter element in a matrix:\n");
	for(i=0;i<m;i++) {
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	}

	for(i=0;i<m;i++) {
		for(j=0;j<n;j++)
			b[j][i]=a[i][j];
	}

	for(i=0;i<n;i++) {
		for(j=0;j<m;j++)
			printf("%d ",b[i][j]);
		printf("\n");
	}
	return 0;
}

Output

Enter the size of the 1st matrix.
2
2
Enter element in a matrix:
1
2
3
4
1 3
2 4

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments