answersLogoWhite

0


Best Answer

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
User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

// 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

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

/*dynamically creates a matrix with 'm' rows and 'n' columns;the matrix can store integer values*/

int **matrix;

int i,j;

matrix=malloc(m*sizeof(int *));

for(i=0;i<m;++i)

matrix[i]=malloc(n*sizeof(int));

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

I want to make dynamic matrix multiplication

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program using dynamic memory allocation to transpose 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


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.


What is the Algorithm for transpose of matrix in python?

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 a flowchart to find the transpose of matrices?

draw the flowchart for transpose of a matrice

Related questions

Write a C program using dynamic memory allocation to find the sum of elements of a matrix?

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.


How do you display matrix in c using dynamic memory allocation?

Memory allocation is not necessary to display a matrix.


Is it true that the transpose of the transpose of a matrix is the original matrix?

yes, it is true that the transpose of the transpose of a matrix is the original matrix


What is the definition of transpose in regards to a 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.


What is a symmetric matrix?

a square matrix that is equal to its transpose


What is transpose of the sparse matrix?

Another sparse matrix.


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


Write a c program using dynamic memory allocation function calloc to find sum of two matrices and also print the resultant matrix?

printf("%s",per&gt;50?:"pass",per&lt;50?:"fail");


How do you find transportation of matrix?

Invert rows and columns to get the transpose of a matrix


Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix?

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&amp;action=edit&amp;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&amp;action=edit&amp;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&amp;A


What is the meaning of transpose?

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 &le; i &le; n and 1 &le; j &le; m.