Transpose of Matrix in C

Previous
Next

Transpose of Matrix:

#include<stdio.h>
int main()
{
	int arr[3][3]={{10,20,30},{40,50,60},{70,80,90}} ,I ,j ,temp;
	printf("Matrix is: \n");
	for(i=0 ; i<3 ; i++)
	{
		for(j=0 ; j<3 ; j++)
		{
			printf("%d\t", arr[i][j]);
		}
		printf("\n");
	}
	
	for(i=0 ; i<3 ; i++)
	{
		for(j=0 ; j<3 ; j++)
		{
			if(i<j)
			{
				temp=arr[i][j];
				arr[i][j]=arr[j][i];
				arr[j][i]=temp;
			}
		}
		printf("\n");
	}
	
	printf("Transpose of matrix: \n");
	for(i=0 ; i<3 ; i++)
	{
		for(j=0 ; j<3 ; j++)
		{
			printf("%d\t", arr[i][j]);
		}
		printf("\n");
	}
}
Previous
Next

Add Comment

Courses Enquiry Form