Simple program confusing!

Try a small program that multiplies two matrices, stuck in this error.Someone plz help, thank in advance. Sr i wrote it in C
E:\Programming\C excercises\Exercise10.3.c||In function 'main':|
E:\Programming\C excercises\Exercise10.3.c|26|error: invalid operands to binary * (have 'int' and 'int *')|
E:\Programming\C excercises\Exercise10.3.c|26|error: expected ';' before 'j'|
E:\Programming\C excercises\Exercise10.3.c|26|error: expected statement before ']' token|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#define SIZE 3

void displayMatrices(int arr[][SIZE], int size)
{
    int i, j;
    for (i = 0; i < size; i++)
    {
        for (j = 0; j < SIZE; j++)
        {
            printf("  %d", arr[i][j]);
        }
        printf("\n");
    }
}

int main()
{
    int arrA[SIZE][SIZE] = {{1, 2, 4}, {4, 2, 5}, {-2, 4, -1}};
    int arrB[SIZE][SIZE] = {{0, 2, 1}, {3, 1, 2}, {2, 1, 0}};
    int arrC[SIZE][SIZE], i, j;
    for (i = 0; i < SIZE; i++)
    {
         for (j = 0; j < SIZE; j++)
         {
             arrC[i][j] = arrA[i][0]*arrB[0][j] + arrA[i][1]*arrB[1][j] + arrA[i][2]*arrB[2]j];
         }
    }
    displayMatrices(arrA, SIZE);
    printf("X\n");
    displayMatrices(arrB, SIZE);
    printf("=\n");
    displayMatrices(arrC, SIZE);
}
Last edited on
I see a typo in this statement

arrC[i][j] = arrA[i][0]*arrB[0][j] + arrA[i][1]*arrB[1][j] + arrA[i][2]*arrB[2]j];

Shall be

arrC[i][j] = arrA[i][0]*arrB[0][j] + arrA[i][1]*arrB[1][j] + arrA[i][2]*arrB[2][j];
Topic archived. No new replies allowed.