static void Main(string[] args)
bool exitProgram = false;
Console.WriteLine("Enter the size of the matrix ([2] for 2x2 or [3] for 3x3): ");
int size = int.Parse(Console.ReadLine());
double[,] matrix1 = ReadMatrix(size);
double[,] matrix2 = ReadMatrix(size);
Console.WriteLine("Select operation:");
Console.WriteLine("1. Dot Product");
Console.WriteLine("2. Cross Product");
Console.WriteLine("3. Trace (Matrix 1)");
Console.WriteLine("4. Trace (Matrix 2)");
Console.WriteLine("5. Transpose (Matrix 1)");
Console.WriteLine("6. Transpose (Matrix 2)");
Console.WriteLine("7. Exit Program");
int choice = int.Parse(Console.ReadLine());
ComputeDotProduct2x2(matrix1, matrix2);
ComputeDotProduct3x3(matrix1, matrix2);
ComputeCrossProduct2x2(matrix1, matrix2);
ComputeCrossProduct3x3(matrix1, matrix2);
ComputeTranspose(matrix1);
ComputeTranspose(matrix2);
Console.WriteLine("Exiting the program...");
Console.WriteLine("Invalid choice. Please try again.");
static double[,] ReadMatrix(int size)
Console.WriteLine($"Enter {size}x{size} matrix elements individually:");
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
Console.Write($"Enter element at position ({i + 1}, {j + 1}): ");
matrix[i, j] = double.Parse(Console.ReadLine());
static void ComputeDotProduct2x2(double[,] matrix1, double[,] matrix2)
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
result += matrix1[i, j] * matrix2[i, j];
Console.WriteLine($"Dot Product: {result}");
static void ComputeDotProduct3x3(double[,] matrix1, double[,] matrix2)
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
result += matrix1[i, j] * matrix2[i, j];
Console.WriteLine($"Dot Product: {result}");
static void ComputeCrossProduct2x2(double[,] matrix1, double[,] matrix2)
double result = matrix1[0, 0] * matrix2[1, 1] - matrix1[0, 1] * matrix2[1, 0];
Console.WriteLine($"Cross Product: {result}");
static void ComputeCrossProduct3x3(double[,] matrix1, double[,] matrix2)
for (int i = 0; i < 3; i++)
result += matrix1[0, i] * (matrix2[1, (i + 1) % 3] * matrix2[2, (i + 2) % 3] - matrix2[1, (i + 2) % 3] * matrix2[2, (i + 1) % 3]);
Console.WriteLine($"Cross Product: {result}");
static void ComputeTrace(double[,] matrix)
for (int i = 0; i < matrix.GetLength(0); i++)
Console.WriteLine($"Trace: {trace}");
static void ComputeTranspose(double[,] matrix)
int rows = matrix.GetLength(0);
int columns = matrix.GetLength(1);
double[,] transpose = new double[columns, rows];
for (int i = 0; i < rows; i++)
for (int j = 0; j < columns; j++)
transpose[j, i] = matrix[i, j];
Console.WriteLine("Transpose:");
for (int i = 0; i < columns; i++)
for (int j = 0; j < rows; j++)
Console.Write(transpose[i, j] + " ");