🏷️ Multiply Two 2x2 Matrices in C

⬅️ Previous

Multiply Two 2x2 Matrices in C

Problem: Write a program to multiply two 2x2 matrices.

🔍 Explanation:

  • Multiply matrices A and B to produce matrix C.
  • Each element of C is the sum of products of corresponding row of A and column of B.
  • Use nested loops for input and multiplication.

✅ C Program:


#include <stdio.h>

int main() {
    int A[2][2], B[2][2], C[2][2];
    
    printf("Enter elements of matrix A (2x2):\n");
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            scanf("%d", &A[i][j]);
        }
    }

    printf("Enter elements of matrix B (2x2):\n");
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            scanf("%d", &B[i][j]);
        }
    }

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            C[i][j] = 0;
            for (int k = 0; k < 2; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }

    printf("Product of matrix A and B is:\n");
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            printf("%d ", C[i][j]);
        }
        printf("\n");
    }

    return 0;
}
  

📤 Sample Output:

Product of matrix A and B is:
19 22
43 50
  

multiply 2x2 matrices in C, matrix multiplication C program, C programming matrix product, multiply two matrices example, 2D array multiplication C, matrix operations C, C programming examples #CProgramming #MatrixMultiplication #2DArray #LearnC #CProgram #CodingInC #CProgrammingTutorial #MatrixOperations #BeginnerCProjects

āĻ•োāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāχ:

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ