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);
}
|