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();
}
Chat with our AI personalities
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));
}
You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.
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
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.
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.
This is a directive, not a question.