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 problem// By Anil Kumar Sahni 20 april 2012 mob 9415683164
#include<stdio.h>
#include<stdlib.h>
void main()
{
int **a;
int ar,ac;
int i,j;
printf("\nenter rows and columns for matrix :");
scanf("%d%d",&ar,&ac);
/* allocate memory for matrix */
a=(int **) malloc(sizeof(int *)*ar);
for( i=0;i<ar;i++)
{
a[i]=(int *) malloc(sizeof(int*)*ac);
}
// matrix input
printf("\n enter matrix one %d by %d\n",ar,a c);
for(i=0;i<ar;i++)
{
for(j=0;j<ac;j++)
{
scanf("%d",&a[i][j]);
}
}
//output matrix
printf("\n Transpose of matrix one and two is\n");
for(i=0;i<ac;i++)
{
for(j=0;j<ar;j++)
{
printf("%d\t",a[j][i]);
}
printf("\n");
}
/*free memory*/
for(i=0;i<ar;i++)
{
free(a[i]);
}
free(a);
} // end of main body
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
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.
a square matrix that is equal to its transpose
Another sparse matrix.
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
Invert rows and columns to get the transpose of a matrix
printf("%s",per>50?:"pass",per<50?:"fail");
Sp[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Answer]]ell chec[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix&action=edit&section=new|Answer it!]]k your answe[[Q/Discuss:Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Disc]][[help/answering questions|guidelin]]Spell check your answeresussionr[[help/signing in|full benefits]] Save C[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 ]][[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix&action=edit&section=new|Answering 'Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix?']]matrix?ancel[[Q/How many animals are in West Texas|How many animals are in West Texas?]][[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a]][[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a Service workshop?]] Service workshop?[[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a Service workshop?]]More Q&A
The transpose of a matrix A is the matrix B that is obtained by swapping the rows and columns of A into the columns and rows of B. In algebraic form, if A = {aij} then B = {aji} is its transpose, where 1 ≤ i ≤ n and 1 ≤ j ≤ m.