Welcome To Shadab's Blog

Programming Blog to learn C# , java, Sql Server 2005 and many more things.





About Me

My photo
Bokaro, Jharkhand, India

Tuesday, November 30, 2010

Program To Implement Matrix Multiplication in C#

using System;

class abc
{
public static void Main()
{

int [,]matrix1=new int[3,3]

{{4,5,7},
{2,4,6},
{1,5,7},
};

int [,]matrix2=new int[3,3]
{
{2,5,1},
{1,2,4},
{3,5,7},
};
int [,]matrix3=new int[3,3];

for(int row=0;row<=2;row++)
{
for(int col=0;col<=2;col++)
{
matrix3[row,col]=matrix1[row,0]*matrix2[0,col]+matrix1[row,1]*matrix2[1,col]+matrix1[row,2]*matrix2[2,col];
}
}
Console.WriteLine(" Resultant Matrix is ");
for(int row=0;row<=2;row++)
{for(int col=0;col<=2;col++)
{
Console.Write(matrix3[row,col]+" ,");
}
Console.WriteLine("\n");
}
}

No comments:

Post a Comment