answersLogoWhite

0

Program to find the Transpose of a Matrix

#include

#include

void main()

{

int i,j,n,t;

int m[5][5];

clrscr();

printf("Enter Order of Matrix : ");

scanf("%d",&n);

printf("Enter Elements of Matrix :\n\n");

for(i=0;i

{

for(j=0;j

{

scanf("%d",&m[i][j]);

}

}

printf("Transpose of the Matrix :\n\n");

for(i=0;i

{

for(j=i+1;j

{

t=m[i][j];

m[i][j]=m[j][i];

m[j][i]=t;

}

}

for(i=0;i

{

for(j=0;j

{

printf("\t%d",m[i][j]);

}

printf("\n");

}

getch();

}

Output:

Enter Order of Matrix : 3

Enter Elements of Matrix :

45 56 96

75 36 15

29 64 81

Transpose of the Matrix :

45 75 29

56 36 64

96 15 81

with out using temp variable:

#include

#include

void main()

{

int i,j,n,t;

int m[5][5];

clrscr();

printf("Enter Order of Matrix : ");

scanf("%d",&n);

printf("Enter Elements of Matrix :\n\n");

for(i=0;i

{

for(j=0;j

{

scanf("%d",&m[i][j]);

}

}

printf("Transpose of the Matrix :\n\n");

for(i=0;i

{

for(j=i+1;j

{

m[j][i]=(m[i][j]+m[j][i]-(m[i][j]=m[j][i]));

}

}

for(i=0;i

{

for(j=0;j

{

printf("\t%d",m[i][j]);

}

printf("\n");

}

getch();

}

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
More answers
Algorithm for the Transpose of a Sparse-Matrix:This is the algorithm that converts a compressed-column sparse matrix into a compressed-row sparse matrix. It computes number of rows in A, compares the cummulative sum to generate row pointers and then iterates over each nonzero entry in A, storing the entry in its corresponding row vector. If the matrix resulted in this procedure is a sparce matrix C and can be interpreted as a matrix in compressed-row form then, C is equal to A. If C is a compressed-column matrix, then C contains Transpose of A.

The code is

cs *cs_transpose(const cs *A, int values)

{

int p,q,j,*cp,*ci,n,m,*Ap,*Ai,*W;

cs *C;

double *Cx,*Ax;

if(!CS_CSC(A))

return(NULL);

m=A->m;

n=A->n;

Ap=A->p;

Ai=A->i;

Ax=A->x;

C=cs_spalloc(n,m,Ap[n],values && Ax,0);

W=cs_calloc(m,sizeof(int));

if(!C!W)

return(cs_done(C,W,NULL,0));

Cp=C->p;

Ci=C->i;

Cx=C->x;

for(p=0;p

W[Ai[p]]++;

cs_cumsum(Cp,W,m);

for(j=0;j

{

for(p=Ap[j];p

{

Ci[q=W[Ai[p]]++]=j;

if(Cx)

Cx[q]=Ax=[p];

}

}

return(cs_done(C,W,NULL,1));

}

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to transpose of a matrix?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


What is matrix programming in C programming?

C Examples on Matrix OperationsA matrix is a rectangular array of numbers or symbols arranged in rows and columns. The following section contains a list of C programs which perform the operations of Addition, Subtraction and Multiplication on the 2 matrices. The section also deals with evaluating the transpose of a given matrix. The transpose of a matrix is the interchange of rows and columns.The section also has programs on finding the trace of 2 matrices, calculating the sum and difference of two matrices. It also has a C program which is used to perform multiplication of a matrix using recursion.C Program to Calculate the Addition or Subtraction & Trace of 2 MatricesC Program to Find the Transpose of a given MatrixC Program to Compute the Product of Two MatricesC Program to Calculate the Sum & Difference of the MatricesC Program to Perform Matrix Multiplication using Recursion


How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


What is a fast-transpose algorithm for sparse matrices?

A fast-transpose is a computer algorithm that quickly transposes a sparse matrix using a relatively small amount of memory. Using arrays normally to record a sparse matrix uses up a lot of memory since many of the matrix's values are zero. In addition, using the normal transpose algorithm to transpose this matrix will take O(cols*elements) amount of time. The fast-transpose algorithm only uses a little memory to record the matrix and takes only O(cols+elements) amount of time, which is efficient considering the number of elements equals cols*rows.


Write a program to print the sum of a sparse matrix?

This is a directive, not a question.