Write a C program to find the Transpose of a matrix.

 TASK-

Write a C program to find the Transpose of a matrix.

Let A = 

  

which has order 3x3 we need to find transpose of a which transforms the columns of a matrix into rows and rows into columns; The transpose of A would be :    

    

CODE:

#include<stdio.h>
int main(){
int col,row; //asking for rows and columns of matrix
printf("Enter number of rows and columns of A: "); //Indication for input
scanf("%d%d",&row,&col); //got number of rows and columns
int mat[row][col],tran[col][row],i,j;
printf("\nEnter the entries of matrix");
for (int i=0;i<row;i++) // One row execute at a time while column number change which applies entry [1,1] then [1,2] and so on.
{
	for (int j=0;j<col;j++) //Number of columns
	{
		printf("Enter entry [%d %d] : ",i+1,j+1); // choosen i+1 and j+1 because the index of matrix starts with 0 but user should see 1;
		scanf("%d",&mat[i][j]);
		printf("\n");
	}
}
/*Making transpose of entered matrix as we know the columns and rows are interchanged hence in the code below you see the entries of trans and mat are enter changed*/
for (int i=0;i<row;i++) // number of rows
{
	for (int j=0;j<col;j++) // number of columns 
	{
		tran[j][i]=mat[i][j]; //process goes here!!!!
			
	}
}
	printf("\n\n\tTranspose : \n");
	//Giving the results (Printing the transpose)
for (int i=0;i<row;i++)
	{
		for (int j=0;j<col;j++)
		{
			printf("\t%d",tran[i][j]);
			
		}
		printf("\n");
	}
getchar();
return 0;
}

Expected Output:






NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

1 Comments

  1. Its fabulous your blogs are helping me in my homework , thanks brother

    ReplyDelete
Post a Comment
Previous Post Next Post