C Program to Multiply Two Matrices - Source Code, Output & Execution Flow

C Program to Multiply Two Matrices

This tutorial explains c program to multiply two matrices with C source code, sample output, and step-by-step execution flow.

#include <stdio.h>
int main() {
    int a[2][2] = {{1, 2}, {3, 4}}, b[2][2] = {{5, 6}, {7, 8}}, c[2][2] = {0};
    int i, j, k;
    for (i = 0; i < 2; i++)
        for (j = 0; j < 2; j++)
            for (k = 0; k < 2; k++) c[i][j] += a[i][k] * b[k][j];
    for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) printf("%d ", c[i][j]); printf("
"); }
    return 0;
}
19 22 
43 50

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.