© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
moshimoshi

❔ Matrix Multiplication

Hi there, I need help understanding the following source code, I have added my questions in the comments.
namespace SolH
{
    class H7
    {
        static int[,] MatrixMultiply(int[,] A, int[,] B)
        {
            int[,] R = new int[A.GetLength(0), B.GetLength(1)];

            for (int i = 0; i < A.GetLength(0); i++)
            {
                for (int j = 0; j < B.GetLength(1); j++)
                {
                    for (int k = 0; k < A.GetLength(1); k++) // why are we looping through A's columns?
                    {
                        R[i, j] = R[i, j] + A[i, k] * B[k, j]; //why do we need to add R[i, j]? Isnt it an empty array after we initialize it? 
                    }
                }
            }
            return R;
        }
namespace SolH
{
    class H7
    {
        static int[,] MatrixMultiply(int[,] A, int[,] B)
        {
            int[,] R = new int[A.GetLength(0), B.GetLength(1)];

            for (int i = 0; i < A.GetLength(0); i++)
            {
                for (int j = 0; j < B.GetLength(1); j++)
                {
                    for (int k = 0; k < A.GetLength(1); k++) // why are we looping through A's columns?
                    {
                        R[i, j] = R[i, j] + A[i, k] * B[k, j]; //why do we need to add R[i, j]? Isnt it an empty array after we initialize it? 
                    }
                }
            }
            return R;
        }


Here is the question: Write a static method MatrixMultiply(int[,] A, int [,] B) that will perform a matrix
multiplication and return another 2 dimensional array.
Screenshot_2023-02-14_at_7.53.53_PM.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

large matrix multiplication
C#CC# / help
15mo ago
✅ Matrix multiplication in C#
C#CC# / help
13mo ago
❔ Matrix dynamic allocation
C#CC# / help
3y ago