Add Two Matrix

Gow.Net
Posted by Gow.Net under C# category on | Points: 40 | Views : 1621
Add Two Matrix

 const int Row = 3;
const int column = 3;
int[,] firstmatrix=new int[Row,column];
int[,] secondmatrix = new int[Row, column];
int[,] Sum = new int[Row, column];
Console.WriteLine("...3 * # Matrix....");

Console.WriteLine("Enter the Firstmatrix..");

for (int i = 0; i < Row; i++)
{
for (int j = 0; j < column; j++)
{
Console.Write("["+i+","+j+"]:");
firstmatrix[i,j] = int.Parse(Console.ReadLine());

}
Console.WriteLine("");

}
Console.WriteLine("Enter the Secondmatrix..");

for (int i = 0; i < Row; i++)
{
for (int j = 0; j < column; j++)
{
Console.Write("[" + i + "," + j + "]:");
secondmatrix[i, j] = int.Parse(Console.ReadLine());

}
Console.WriteLine("");

}
Console.WriteLine("Firstr Matrix...");
for (int i = 0; i < Row; i++)
{
for (int j = 0; j < column; j++)
{
// Console.Write("[" + i + "," + j + "]:");
Console.Write(""+firstmatrix[i, j]);
Console.Write(" ");
}
Console.WriteLine(" ");

}
Console.WriteLine("Second Matrix...");
for (int i = 0; i < Row; i++)
{
for (int j = 0; j < column; j++)
{
// Console.Write("[" + i + "," + j + "]:");
Console.Write("" + secondmatrix[i, j]);
Console.Write(" ");
}
Console.WriteLine(" ");

}

Console.WriteLine("Addtwo Matrix");
for (int i = 0; i < Row; i++)
{
for (int j = 0; j < column; j++)
{
// Console.Write("[" + i + "," + j + "]:");
Sum[i,j]=firstmatrix[i, j]+secondmatrix[i, j];
}
Console.WriteLine(" ");

}
for (int i = 0; i < Row; i++)
{
for (int j = 0; j < column; j++)
{
Console.Write("" + Sum[i, j]);
Console.Write(" ");
}
Console.WriteLine(" ");

}
Console.ReadKey();

Comments or Responses

Login to post response