I''m working on a project that will add,multipy,sub tract and divide a matrix. Each one is suppose to be display in a method. I can figure out the addition and subtraction but not the multipication and divison. I also needs help with user input. The user suppose to enter the values in the Display Method, but I'm having trouble with the Console.Intt32. My code is below.
[CODE]
using System;
public class Matrix
{
public static void Main(string[] args)
{
int[,] matrix1 = { {1, 2 }, { 3, 4 } };
int[,] matrix2 = { { 2, 3 }, { 4, 5 } };
int[,] matrix3 = new int [2,2];
DisplayMatrix(m atrix1);
Console.WriteLi ne();
DisplayMatrix(m atrix2);
AddMatrix(matri x1, matrix2, matrix3);
SubtractMatrix( matrix1, matrix2, matrix3);
}
public static void DisplayMatrix(i nt[,] array)
{
for (int row=0; row < array.GetLength (0); row++)
{
for (int column = 0; column < array.GetLength (1); column++)
array=Convert.T oInt(Console.Re adLine());
Console.Write(" {0}", array[ row, column]);
Console.WriteLi ne();
}
}
public static void AddMatrix(int[,] array1, int [,] array2, int[,] array3)
{
for(int row=0; row< array1.GetLengt h(0); row++)
{
for(int column=0; column <array1.GetLeng th( 1 ); column++)
array3[row, column] = array1 [row, column] + array2 [row, column];
}
for (int row = 0; row < array1.GetLengt h(0); row++)
{
for (int column = 0; column < array1.GetLengt h(1); column++)
Console.Write(" {0}", array3[row, column]);
}
Console.WriteLi ne();
}
public static void SubtractMatrix( int[,] array1, int[,] array2, int[,] array3)
{
for (int row = 0; row < array1.GetLengt h(0); row++)
{
for (int column = 0; column < array1.GetLengt h(1); column++)
array3[row, column] = array1[row, column] - array2[row, column];
}
for (int row = 0; row < array1.GetLengt h(0); row++)
{
for (int column = 0; column < array1.GetLengt h(1); column++)
Console.Write(" {0}", array3[row, column]);
}
Console.WriteLi ne();
}
}
{/CODE}
[CODE]
using System;
public class Matrix
{
public static void Main(string[] args)
{
int[,] matrix1 = { {1, 2 }, { 3, 4 } };
int[,] matrix2 = { { 2, 3 }, { 4, 5 } };
int[,] matrix3 = new int [2,2];
DisplayMatrix(m atrix1);
Console.WriteLi ne();
DisplayMatrix(m atrix2);
AddMatrix(matri x1, matrix2, matrix3);
SubtractMatrix( matrix1, matrix2, matrix3);
}
public static void DisplayMatrix(i nt[,] array)
{
for (int row=0; row < array.GetLength (0); row++)
{
for (int column = 0; column < array.GetLength (1); column++)
array=Convert.T oInt(Console.Re adLine());
Console.Write(" {0}", array[ row, column]);
Console.WriteLi ne();
}
}
public static void AddMatrix(int[,] array1, int [,] array2, int[,] array3)
{
for(int row=0; row< array1.GetLengt h(0); row++)
{
for(int column=0; column <array1.GetLeng th( 1 ); column++)
array3[row, column] = array1 [row, column] + array2 [row, column];
}
for (int row = 0; row < array1.GetLengt h(0); row++)
{
for (int column = 0; column < array1.GetLengt h(1); column++)
Console.Write(" {0}", array3[row, column]);
}
Console.WriteLi ne();
}
public static void SubtractMatrix( int[,] array1, int[,] array2, int[,] array3)
{
for (int row = 0; row < array1.GetLengt h(0); row++)
{
for (int column = 0; column < array1.GetLengt h(1); column++)
array3[row, column] = array1[row, column] - array2[row, column];
}
for (int row = 0; row < array1.GetLengt h(0); row++)
{
for (int column = 0; column < array1.GetLengt h(1); column++)
Console.Write(" {0}", array3[row, column]);
}
Console.WriteLi ne();
}
}
{/CODE}
Comment