#K4671. 2x2 Matrix Operations
2x2 Matrix Operations
2x2 Matrix Operations
This problem requires you to implement a Matrix class that represents a 2x2 matrix.
You need to implement two functionalities:
- Determinant Calculation: Compute the determinant of the matrix using the formula \(\text{Det} = a \times d - b \times c\). The matrix is represented as \(\begin{pmatrix} a & b \\ c & d \end{pmatrix}\).
- Matrix Multiplication: Multiply two 2x2 matrices using standard matrix multiplication.
You will be given input via stdin and must output the result to stdout.
inputFormat
The first integer in the input denotes the operation type (op):
-
If op = 1, you will be given a single 2x2 matrix. The next line contains four space-separated integers a, b, c, and d representing the matrix elements in row-major order.
-
If op = 2, you will be given two 2x2 matrices. The next line contains eight space-separated integers: the first four are for the first matrix and the next four are for the second matrix (each in row-major order).
outputFormat
For op = 1: output a single integer representing the determinant of the matrix. For op = 2: output four space-separated integers representing the resulting matrix from the multiplication (in row-major order).## sample
1
1 2 3 4
-2