I want to find the product of two matrix using a function without using for loop?
Help is really appreciated.

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by firstPerson

I want to find the product of two matrix using a function without using for loop?
Help is really appreciated.

Why don't you want to use a for-loop? That would be the easiest way. Any for-loop can be converted to a while or do-while loop, and vice versa.

You're looking at using nested loops, whatever type of loops those are. If you're multiplying an m x n matrix by an n x p matrix, you'll end up with an m x p matrix. The (a, b) element of the resulting n x p matrix will be calculated by multiplying the ath row of the m x n matrix by the bth column of the n x p matrix. You get that by setting up a sum variable, initializing it to 0, setting up a loop, going through it n times, each time multiplying two numbers and adding it to the sum. That's the innermost loop.

The outermost loop will be traversed m times (number of rows in the first matrix). The middle loop will be traversed p times (number of columns in the second matrix).

So you have a loop within a loop within a loop. I'd make them all for loops, but as mentioned, any for-loop can be turned into a while or do-while loop.

How to find the product of two matrix ?

The tittle should instead be :