img
Question:
Published on: 25 April, 2024

Write a C program to transpose of a matrix.

Answer:

 

#include<stdio.h>
#include<conio.h>
main()
{
	int a[10][10],b[10][10],m,n,i,j;
	printf("\n enter the dimension of the matrix");
	scanf("%d %d",&m,&n);
	printf("\n enter the elements(row wise)");
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		scanf("%d",&a[i][j]);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		b[i][j]=a[j][i];
	}
	printf("\n the transpose matrix is \n");
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			printf("%d\t",b[i][j]);
	printf("\n");
	}
	getch();
}


Output:

Random questions