wkid87

10-09-2007, 04:21 PM

Hello, I need help with three things. I'm during a matrix/multi-dimesional array that is a size 2 x 2. The user must enter the values after the user enter the values the program must add, subtract, multipy, and divide. I can not figure out how the user will enter the values and I can figure out the multiplication and divison. I tried doing a Console.Int32 but I was getting an error. I tried during a for statement just like I did with addition and I was not getting the right number. Any help will be appreciate. Thanks! Here is my 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(matrix1);

Console.WriteLine();

DisplayMatrix(matrix2);

AddMatrix(matrix1, matrix2, matrix3);

SubtractMatrix(matrix1, matrix2, matrix3);

}

public static void DisplayMatrix(int[,] array)

{

for (int row=0; row < array.GetLength(0); row++)

{

for (int column = 0; column < array.GetLength(1); column++)

array=Convert.ToInt(Console.ReadLine());

Console.Write("{0}", array[ row, column]);

Console.WriteLine();

}

}

public static void AddMatrix(int[,] array1, int [,] array2, int[,] array3)

{

for(int row=0; row< array1.GetLength(0); row++)

{

for(int column=0; column <array1.GetLength( 1 ); column++)

array3[row, column] = array1 [row, column] + array2 [row, column];

}

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)

Console.Write("{0}", array3[row, column]);

}

Console.WriteLine();

}

public static void SubtractMatrix(int[,] array1, int[,] array2, int[,] array3)

{

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)

array3[row, column] = array1[row, column] - array2[row, column];

}

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)

Console.Write("{0}", array3[row, column]);

}

Console.WriteLine();

}

}

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(matrix1);

Console.WriteLine();

DisplayMatrix(matrix2);

AddMatrix(matrix1, matrix2, matrix3);

SubtractMatrix(matrix1, matrix2, matrix3);

}

public static void DisplayMatrix(int[,] array)

{

for (int row=0; row < array.GetLength(0); row++)

{

for (int column = 0; column < array.GetLength(1); column++)

array=Convert.ToInt(Console.ReadLine());

Console.Write("{0}", array[ row, column]);

Console.WriteLine();

}

}

public static void AddMatrix(int[,] array1, int [,] array2, int[,] array3)

{

for(int row=0; row< array1.GetLength(0); row++)

{

for(int column=0; column <array1.GetLength( 1 ); column++)

array3[row, column] = array1 [row, column] + array2 [row, column];

}

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)

Console.Write("{0}", array3[row, column]);

}

Console.WriteLine();

}

public static void SubtractMatrix(int[,] array1, int[,] array2, int[,] array3)

{

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)

array3[row, column] = array1[row, column] - array2[row, column];

}

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)

Console.Write("{0}", array3[row, column]);

}

Console.WriteLine();

}

}