I got it figure out. Instead of displaying my results in each Method I need it to be display in the Answer Method. I need to pass the arguments to the Answer Method The next problem I having is the answer that it is displaying is not in a matrix but in a straight line. Here are the directions. I want to make sure I have this right:
Write a method that sets data size and the elements for each of the matrices.
Write a method that multipies the two matrices.
Write a method that dds the two matrices.
Write a method that subtract one matrix from the other.
Write a method nicely dsplay the matrices.
The main Method should test the class. The method names shall be selected to reflect what the method does.
Write a method that sets data size and the elements for each of the matrices.
Write a method that multipies the two matrices.
Write a method that dds the two matrices.
Write a method that subtract one matrix from the other.
Write a method nicely dsplay the matrices.
The main Method should test the class. The method names shall be selected to reflect what the method does.
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 = { { 0, 0 }, { 0, 0 } }; InputMatrix(matrix1); Console.WriteLine(); InputMatrix(matrix2); Console.WriteLine(); AddMatrix(matrix1, matrix2, matrix3); SubtractMatrix(matrix1, matrix2, matrix3); Multipy(matrix1, matrix2, matrix3); } public static void InputMatrix(int[,] array) { for (int row = 0; row < array.GetLength(0); row++) { for (int column = 0; column < array.GetLength(1); column++) { Console.WriteLine("Enter element {0}, {1}", row, column); array[row, column] = Convert.ToInt32(Console.ReadLine()); } 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]; Console.WriteLine(); } for (int row = 0; row < array1.GetLength(0); row++) { for (int column = 0; column < array1.GetLength(1); 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(); } public static void Multipy(int[,] array1, int[,] array2, int[,] array3) { for (int row = 0; row < array1.GetLength(0); row++) { for (int column = 0; column < array2.GetLength(1); column++) { for (int a = 0; a < array1.GetLength(1); a++) array3[row, column] += array1[row, a] * array2[a, column]; Console.Write("{0}", array3[row, column]); } Console.WriteLine(); } } public static void Answers(int[,] array3) { } }
Comment