MHB How can I effectively perform matrix operations in C programming language?

AI Thread Summary
The discussion centers on learning how to perform matrix addition and multiplication using the C programming language. The user is specifically tasked with creating two 2x2 matrices and implementing the required operations. For matrix addition, the sum of two matrices A and B is obtained by adding corresponding elements. For matrix multiplication, the product is calculated by summing the products of the elements from the rows of the first matrix and the columns of the second. The user requests complete code examples for these operations in C, expressing a desire for assistance in correcting any mistakes in their attempts. The conversation emphasizes the importance of understanding both the mathematical concepts and the corresponding C syntax for matrix operations.
Henry R
Messages
25
Reaction score
0
Good day everyone. I'm learning C language at the moment. Plus, matrix is bit harder. It just I couldn't understand how to write it in C programming language. Plus, it's maths calculations.
I have to use C language for this, not C++.Here's the question :
A matrix is an array of numbers which can be used in calculations. You are required to create a two 2 x 2 matrices, and perform a matrix addition and a matrix multiplication.

View attachment 3477

a) The sum of A and B, denoted by A+B, is the m x n matrix, which is obtained by adding elements in the corresponding positions.
View attachment 3478

b) The product of A and B denoted by AB, is m × n matrix with (i,j)th entry equal to the sum of the products of the corresponding elements from the ith row of A and the jth column of B. In other words, if AB = [cij], then

View attachment 3479
 

Attachments

  • 1.PNG
    1.PNG
    1.4 KB · Views: 138
  • 2.PNG
    2.PNG
    809 bytes · Views: 144
  • 3.PNG
    3.PNG
    1.9 KB · Views: 130
Technology news on Phys.org
The following should create a 2x2 array

Code:
int a[2][2] = {{1,2},{3,4}};
//where a[0][0] = 1 , a[0][1] = 1 , a[1][0] = 1 , a[1][1] = 1

to get or a set an element you can use $a[j]$ where $i$ represents the row and $j$ represents the column.
 
ZaidAlyafey said:
The following should create a 2x2 array

Code:
int a[2][2] = {{1,2},{3,4}};
//where a[0][0] = 1 , a[0][1] = 1 , a[1][0] = 1 , a[1][1] = 1

to get or a set an element you can use $a[j]$ where $i$ represents the row and $j$ represents the column.


How about the code? I mean, can you show me the complete code?;) Sorry, if this sound annoying. But, I try my best on programming.
 
Can you post your attempt ? then if there are mistakes we can correct them.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
25
Views
2K
Replies
5
Views
3K
Replies
9
Views
1K
Replies
15
Views
4K
Replies
21
Views
3K
Replies
22
Views
4K
Back
Top