
Problem
Solution
Submissions
Find the Determinant of a 2x2 Matrix
Certification: Basic Level
Accuracy: 100%
Submissions: 5
Points: 5
Write a C++ program to find the determinant of a 2x2 matrix. The determinant of a 2x2 matrix is calculated as (ad - bc), where the matrix is [[a, b], [c, d]].
Example 1
- Input: matrix = [ [1, 2], [3, 4] ]
- Output: -2
- Explanation:
- Step 1: Identify the values a=1, b=2, c=3, d=4 in the matrix.
- Step 2: Apply the determinant formula: det = ad - bc.
- Step 3: Calculate det = (1 × 4) - (2 × 3) = 4 - 6 = -2.
- Step 4: Return the determinant value -2.
Example 2
- Input: matrix = [ [5, 6], [7, 8] ]
- Output: -2
- Explanation:
- Step 1: Identify the values a=5, b=6, c=7, d=8 in the matrix.
- Step 2: Apply the determinant formula: det = ad - bc.
- Step 3: Calculate det = (5 × 8) - (6 × 7) = 40 - 42 = -2.
- Step 4: Return the determinant value -2.
Constraints
- The matrix must be a 2x2 matrix
- The elements of the matrix are integers
- Time Complexity: O(1)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use the formula (ad - bc) to calculate the determinant.
- Ensure that the input matrix is a 2x2 matrix.