Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Suppose A,B,C are mxm matrices.what does the following algorithm compute?(here A(i,j) denotes (i,j)^th entry of matrix A).
for i = 1 to m 
  for j = 1 to m 
     for k = 1 to m 
        C(i,j) = A(i,k)* B(k,j)+C(i,j)
     end 
  end 
end


What I have tried:

Tried every possible way but it seems hard to solve.
Posted
Updated 6-Jan-23 22:34pm
v2
Comments
jeron1 6-Jan-23 11:27am    
Perhaps you could post one of the 'every possible ways' that you have tried, then ask a specific question. Folks here will be more than willing to help.

The code computes
C = C + AB
 
Share this answer
 
You have answered your own question. The algorithm computes
C
C(i,j) += A(i,k)* B(k,j)
for every location in the matrix.
 
Share this answer
 
Comments
Shivam Siddharth 7-Jan-23 10:14am    
what does k loop do? i and j are rows and columns
Rick York 7-Jan-23 11:55am    
k is used as an index into the A and B matrices.
RedDk 7-Jan-23 14:10pm    
Ahah! "A and B matrices" ... that's calling a spade a spade!
See Matrices[^], for details of how to access elements of a matrix.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900