C# Program to perform Matrix Multiplication
You are Here:
Perform Matrix Multiplication
In the following example, we will multiply the two given matrices (two-dimensional arrays).
Example
C# Compiler
using System;
namespace myApp
{
class Program
{
static void Main(string[] args)
{
int i, j, k;
int[,] arr1 = {
{1, 1, 1},
{1, 1, 1},
{1, 1, 1}
};
int[,] arr2 = {
{2, 2, 2},
{2, 2, 2},
{2, 2, 2}
};
int[,] arr3 = new int[3, 3];
Console.WriteLine("Matrix A (3 x 3):");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
Console.Write("{0} ", arr1[i, j]);
Console.WriteLine();
}
Console.WriteLine("\nMatrix B (3 x 3):");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
Console.Write("{0} ", arr2[i, j]);
Console.WriteLine();
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
for(k=0; k<3; k++)
arr3[i, j] = arr3[i, j] + arr1[i, k] * arr2[k, j];
}
}
Console.WriteLine("\nMatrix Multiplication (A x B):");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
Console.Write("{0} ", arr3[1, 1]);
Console.WriteLine();
}
}
}
}
Output
Matrix A (3 x 3):
1 1 1
1 1 1
1 1 1
Matrix B (3 x 3):
2 2 2
2 2 2
2 2 2
Matrix Multiplication (A x B):
6 6 6
6 6 6
6 6 6
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on C# with examples for quick and easy learning.
We are working to cover every Single Concept in C#.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.