Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C++ multiplying matrices using dynamic arrays, loop not working?

jmizza

New Coder
Hi, so I'm trying to write a program that takes two square matrices of any size, multiplies them, and output the product using dynamic arrays for an assignment. I'm not having any errors but I'm not getting the correct product matrix. This is the code for my loop:

Code:
for(int row = 0; row < r; row++)
    {
      int col;
      for (col = 0; col < s; col++)
      {
        E[row][col] += C[row][col] * D[col][row];
      }
    }

And this is the result I'm getting:

Code:
Enter the dimensions of your matrices: 3 3

Enter the values of your first matrix: 1 2 3 4 5 6 7 8 9
Enter the values of your second matrix: 1 2 3 4 5 6 7 8 9

The product of:

   1   2   3
   4   5   6
   7   8   9

and:

   1   2   3
   4   5   6
   7   8   9

is:

   1   8  21
   8  25  48
  21  48  81
 

New Threads

Buy us a coffee!

Back
Top Bottom