answersLogoWhite

0


Best Answer

You took an example of The Product AB is determined as the dot products of the ith row in A and the jth column in B,placed in ith row and jth column of the resulting m x p matrix C.

so: this may help you.

#include <stdio.h>

#include <stdlib.h>

// function prototypes

void Matrix_Mult( int a1[][3], int a2[][4], int a3[][4] );

void Matrix_MultAlt( int a1[][3], int a2[][4], int a3[][4] );

int dot3(const int a1[][3], const int a2[][4], int row, int col);

void PrnNx4 (int ar[][4], int n);

//---------------------------------------------------------------------------------

// Function: main(void)

// Description:

// demonstration of Matrix Multiplication

//

// Programmer: Paul Bladek

//

// Date: 10/31/2001

//

// Version: 1.0

//

// Environment: Hardware:IBM Pentium 4

// Software: Microsoft XP with .NET framework for execution;

// Compiles under Microsoft Visual C++.Net 2005

//

// Calls: Matrix_Mult(int a1[][3], int a2[][4], int a3[][4])

// Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4])

// PrnNx4(int ar[][4]

//

//

// Parameters: int a1[][3] -- left matrix

// int a2[][4] -- right matrix

// int a3[][4] -- answer matrix

//

// Returns: EXIT_SUCCESS

// ------------------------------------------------------------------------------

int main(void)

{

int A[2][3] = {{1, 3, 4},

{2, 0, 1}},

B[3][4] = {{1, 2, 3, 1},

{2, 2, 2, 2},

{3, 2, 1, 4}},

C[2][4] = {{0, 0, 0, 0},

{0, 0, 0, 0}};

Matrix_Mult(A, B, C);

PrnNx4(C, 2);

Matrix_MultAlt(A, B, C); // alternate form that calls dot3

PrnNx4(C, 2);

return EXIT_SUCCESS;

}

//---------------------------------------------------------------------------------

// Function: Matrix_Mult(int a1[][3], int a2[][4], int a3[][4])

// Description:

// multiplies a 2X3 matrix by a 3X4 matrix

//

// Programmer: Paul Bladek

//

// Date: 10/31/2001

//

// Version: 1.0

//

// Environment: Hardware:IBM Pentium 4

// Software: Microsoft XP with .NET framework for execution;

// Compiles under Microsoft Visual C++.Net 2005

//

// Calls: None

//

// Called By: main()

//

// Parameters: int a1[][3] -- left matrix

// int a2[][3] -- right matrix

// int a3[][3] -- answer matrix

// ------------------------------------------------------------------------------

void Matrix_Mult(int a1[][3], int a2[][4], int a3[][4])

{

int i = 0;

int j = 0;

int k = 0;

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

for( j = 0; j < 4; j++)

for( k = 0; k < 3; k++)

a3[i][j] += a1[i][k] * a2[k][j];

}

//---------------------------------------------------------------------------------

// Function: Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4])

// Description:

// multiplies a 2X3 matrix by a 3X4 matrix -- Alternate Form

//

// Programmer: Paul Bladek

//

// Date: 10/31/2001

//

// Version: 1.0

//

// Environment: Hardware:IBM Pentium 4

// Software: Microsoft XP with .NET framework for execution;

// Compiles under Microsoft Visual C++.Net 2005

//

// Calls: dot3(const int a1[][3], const int a2[][4], int row, int col)

//

// Called By: main()

//

// Parameters: int a1[][3] -- left matrix

// int a2[][3] -- right matrix

// int a3[][3] -- answer matrix

// ------------------------------------------------------------------------------

void Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4])

{

int i = 0;

int j = 0;

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

for( j = 0; j < 4; j++)

a3[i][j] = dot3(a1, a2, i, j);

}

//---------------------------------------------------------------------------------

// Function: dot3(const int a1[][3], const int a2[][4], int row, int col)

// Description:

// dot product of a1 row and a2 col

//

// Programmer: Paul Bladek

//

// Date: 10/31/2001

//

// Version: 1.0

//

// Environment: Hardware:IBM Pentium 4

// Software: Microsoft XP with .NET framework for execution;

// Compiles under Microsoft Visual C++.Net 2005

//

// Calls: None

//

// Called By: Matrix_MultAlt(int a1[][3], int a2[][4], int a3[][4])

//

// Parameters: int a1[][3] -- left matrix

// int a2[][3] -- right matrix

// int row -- the row number

// int col -- the column number

//

// Returns: the dot product

// ------------------------------------------------------------------------------

int dot3(const int a1[][3], const int a2[][4], int row, int col)

{

int k = 0;

int sum = 0;

for( k = 0; k < 3; k++)

sum += a1[row][k] * a2[k][col];

return sum;

}

//---------------------------------------------------------------------------------

// Function: PrnNx4(int ar[][4], int n)

// Description:

// prints out an NX4 matrix

//

// Programmer: Paul Bladek

//

// Date: 10/31/2001

//

// Version: 1.0

//

// Environment: Hardware:IBM Pentium 4

// Software: Microsoft XP with .NET framework for execution;

// Compiles under Microsoft Visual C++.Net 2005

//

// Called By: main()

//

// Parameters: int ar[][4] -- matrix to print

// int n -- number of elements

// ------------------------------------------------------------------------------

void PrnNx4 (int ar[][4], int n)

{

int i = 0;

int j = 0;

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

{

for( j = 0; j < 4; j++)

printf("%4d", ar[i][j]);

putchar('\n');

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you do matrix multiplication in c using structure?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

C program for matrix multiplication using dynamic memory alllocation?

Poor boy


Program to display multiplication of two matrix?

The matrix multiplication in c language : c program is used to multiply matrices with two dimensional array. This program multiplies two matrices which will be entered by the user.


What are disadvantages of sparse matrix in data structure using c?

what is the disadvantage of sparse 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


C plus plus program -matrix multiplication using class?

for(int i=0;i


How do you find matrix in c?

using multidimensional array


How do you implement Hadamard matrix in c?

A Hadamard Matrix is a square matrix composed of 1 or -1. Using a square matrix system the hadamard matrix could be created


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

Memory allocation is not necessary to display a matrix.


Write a c program for matrix addition using function?

#include&lt;


If A is any mxn such that AB and BA are both defined show that B is an mxn matrix?

By rule of matrix multiplication the number of rows in the first matrix must equal the number of rows in the second matrix. If A is an axb matrix and B is a cxd matrix, then a = d. Then if BA is defined, then c = b. This means that B is not necessarily mxn, but must be nxm.


What is the product of matrix A and C?

It's matrix C.


How do you create modules in c language?

by using structure in c.........