---
title: "Significance of arrays; multiply 3×3 matrices"
subject: "Computer Programming"
chapter: 7
key: "semester_1/computer_programming:array-significance-multiply-matrices"
source: https://www.bctengineer.com/q/semester_1/computer_programming/array-significance-multiply-matrices
site: BCT Engineering
---

# Significance of arrays; multiply 3×3 matrices

Computer Programming · Chapter 7: Arrays and Strings

- Asked in: 2068 Chaitra, 2+6 marks
- Video: [C Program for Matrix Multiplication (Part 1)](https://www.youtube.com/watch?v=aAFP5wsmH2k) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/array-significance-multiply-matrices
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-7

## Question

Write down the significance of array in C. Write a program to multiply two 3×3 matrix. Two matrix are input from main ( ) function and pass to a user defined function with argument with array. The result is also displayed from main ( ) function.

## Short answer

Arrays store many values of one type, accessible by index, stored consecutively, efficient for loops and matrices. The multiply program reads two 3x3 matrices, passes them to multiply() which computes c[i][j] = sum of a[i][k]*b[k][j] for k=0..2, then displays product in main().

## Answer

#### Significance of arrays
- An array stores many values of the same type under one name, so a hundred variables are not needed.
- Elements are reached quickly by index (`a[i]`), which works well with loops.
- Data are stored in consecutive memory, so traversal and processing are simple and fast.
- Needed for lists, tables and matrices, and as the base for strings, sorting, searching and many data structures.
- Arrays are passed to functions easily, so one function can work on a whole set of data.

#### Program: multiply two 3×3 matrices
c[i][j] = Σ a[i][k] × b[k][j] for k = 0 to 2. The matrices are read in `main()`, passed to `multiply()` and the product is displayed in `main()`.

```c
#include <stdio.h>

void multiply(int a[3][3], int b[3][3], int c[3][3])
{
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++) {
            c[i][j] = 0;
            for (int k = 0; k < 3; k++)
                c[i][j] += a[i][k] * b[k][j];
        }
}

int main(void)
{
    int a[3][3], b[3][3], c[3][3];
    printf("Enter first matrix: ");
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            scanf("%d", &a[i][j]);
    printf("Enter second matrix: ");
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            scanf("%d", &b[i][j]);

    multiply(a, b, c);
    printf("Product:\n");
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++)
            printf("%5d", c[i][j]);
        printf("\n");
    }
    return 0;
}
```

**Sample run** (second matrix is diag(1,1,2))

Input: `1 2 3 4 5 6 7 8 9 1 0 0 0 1 0 0 0 2`

```text
Enter first matrix: Enter second matrix: Product:
    1    2    6
    4    5   12
    7    8   18
```

The third column is doubled, which matches the multiplier matrix.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is a key significance of arrays?
   A. They store values of different types together
   B. They use less memory than variables always
   C. Many same-type values can be stored under one name and accessed by index in loops
   D. They need no declaration
   Answer: C. An array avoids many separate variables. (Key point: Why arrays)

2. How is c[i][j] computed for matrix product?
   A. Sum of a[i][k] * b[k][j] over k
   B. a[i][j] * b[i][j]
   C. a[i][j] + b[i][j]
   D. a[k][i] * b[j][k] for only k = 0
   Answer: A. Row i of a is combined with column j of b. (Key point: Multiplication formula)

3. Why is c[i][j] = 0 set before the inner loop?
   A. To free memory
   B. To transpose c
   C. Because += accumulates and would otherwise start from garbage
   D. Because C requires it for 3x3 only
   Answer: C. The accumulator must start at zero. (Key point: Initialise result)

## Related in Computer Programming

- [Pass array; transpose 3×3 matrix](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-array-transpose-3x3) — Computer Programming, chapter 7
- [Significance of user defined functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asignificance-user-defined-functions) — Computer Programming, chapter 6
- [Array overflow/underflow; add two arrays](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aarray-overflow-underflow-add) — Computer Programming, chapter 7
- [Switch versus user defined function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-user-function) — Computer Programming, chapter 5
- [Significance of main() function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asignificance-of-main) — Computer Programming, chapter 6
- [Pass student array; display passed students](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-whole-array-student-info) — Computer Programming, chapter 7

## Related in other subjects

- [Cascaded two-ports: ABCD matrices multiply](https://www.bctengineer.com/question.md?key=semester_3%2Felectrical_circuit_theory%3Acascade-transmission-matrix-product) — Electrical Circuit Theory, chapter 7
- [Protected specifier; student/test/result program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprotected-three-class-program) — Object Oriented Programming, chapter 6
- [Default argument and overloading program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adefault-arg-overloading-program) — Object Oriented Programming, chapter 3
- [Exception with argument and specification program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aexception-program-arg-specification) — Object Oriented Programming, chapter 10
