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

Recommended Answers

All 2 Replies

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 :

How to use Google Properly

If you know how to multiply 2 matrices with for loops then you know
how to do with with other types of loop, provided you know about
the other loops.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.