Type your answervoid main()
{
int **a,**b,**c;
//int c[3][3];
int a_r,a_c,b_r,b_c;
int i,j,k;
clrscr();
again:
printf("\nenter rows and columns for matrix one:");
scanf("d",&a_r,&a_c);
printf("\nenter rows and columns for matrix two:");
scanf("d",&b_r,&b_c);
if(a_c!=b_r )
{
printf("\ncan not multiply");
goto again;
}
/* allocate memory for matrix one */
a=(int **) malloc(sizeof(int *),a_r);
for( i=0;i {
a[i]=(int *) malloc(sizeof(int*)*a_c);
}
/* allocate memory for matrix two */
b=(int **) malloc(sizeof(int)*b_r);
for( i=0;i {
b[i]=(int *) malloc(sizeof(int*)*b_c);
}
/* allocate memory for sum matrix */
c=(int **) malloc(sizeof(int *)*a_r);
for( i=0;i {
c[i]=(int *) malloc(sizeof(int)*b_c);
}
printf("\n enter matrix one %d by %d\n",a_r,a_c);
for(i=0;i {
for(j=0;j {
scanf("%d",&a[i][j]);
}
}
printf("\n enter matrix two %d by %d\n",b_r,b_c);
for(i=0;i {
for(j=0;j {
scanf("%d",&b[i][j]);
}
}
/*initialize product matrix */
for(i=0;i {
for(j=0;j {
c[i][j]=0;
}
}
/* multiply matrix one and matrix two */
for(i=0;i {
for(j=0;j {
for(k=0;k {
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
/* display result */
printf("\n Product of matrix one and two is\n");
for(i=0;i {
for(j=0;j {
printf("%d\t",c[i][j]);
}
printf("\n");
}
/*free memory*/
for(i=0;i {
free(a[i]);
}
free(a);
for(i=0;i {
free(b[i]);
}
free(b);
for(i=0;i {
free(c[i]);
}
free(c);
printf("\npress any key");
getch();
}
I would suggest you go to
http://code.freefeast.info/matrix-multiplication-using-pointers-in-c-dynamic-matrix-multiplication-in-c/
It has got a well formatted and commented code for this problemYou 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
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.
Algorithm: transpose Input: a matrix M[x][y] Output: the transpose of M (a matrix of order y * x) allocate N[y][x] for r = 0 to x-1 // iterate over rows for c = 0 to y-1 // iterate over columns N[c][r] = M[r][c] next c next r return N
draw the flowchart for transpose of a matrice
Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements.
Memory allocation is not necessary to display a matrix.
yes, it is true that the transpose of the transpose of a matrix is the original matrix
The Transpose of a MatrixThe matrix of order n x m obtained by interchanging the rows and columns of the m X n matrix, A, is called the transpose of A and is denoted by A' or AT.
Another sparse matrix.
a square matrix that is equal to its transpose
To write a C program to find the adjoint of a matrix, first, you need to create a function to calculate the cofactor of each element in the matrix. Then, construct the adjoint by transposing the cofactor matrix. The program should read the matrix size and elements from user input, compute the cofactors using nested loops, and finally display the adjoint matrix by transposing the cofactor matrix. Make sure to handle memory allocation for dynamic matrices if needed.
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
To find a unitary matrix, one must first square the matrix and then take the conjugate transpose of the result. If the conjugate transpose of the squared matrix is equal to the identity matrix, then the original matrix is unitary.
Invert rows and columns to get the transpose of a matrix
printf("%s",per>50?:"pass",per<50?:"fail");