lots of stuff
[assignments.git] / lab / lab7 / matrix.c
CommitLineData
165869e8 1#include "matrix.h"
2#include <string.h>
3#include <stdio.h>
4
5const int gLeft[MATRIX_SIZE][MATRIX_SIZE];
6const int gRight[MATRIX_SIZE][MATRIX_SIZE];
7
8void set_left(int matrix[MATRIX_SIZE][MATRIX_SIZE])
9{
10 memcpy(gLeft, matrix, MATRIX_SIZE * MATRIX_SIZE * sizeof(int));
11 return;
12}
13
14void set_right(int matrix[MATRIX_SIZE][MATRIX_SIZE])
15{
16 memcpy(gRight, matrix, MATRIX_SIZE * MATRIX_SIZE * sizeof(int));
17 return;
18}
19
20int matrix_multiply(int row, int col)
21{
22 int sum = 0;
23 int i = 0;
24 for(i = 0; i < MATRIX_SIZE; ++i)
25 {
26 sum += (gLeft[row][i] * gRight[i][col]);
27 }
28 if (((row + col) % 10) == 0)
29 {
30 sleep(rand() % 3);
31 }
32 return sum;
33}
34
35void print_matrix(int matrix[MATRIX_SIZE][MATRIX_SIZE])
36{
37 int row, col;
38 for(row = 0; row < MATRIX_SIZE; ++row)
39 {
40 for(col = 0; col < MATRIX_SIZE; ++col)
41 {
42 printf("%d,", matrix[row][col]);
43 }
44 printf("\n");
45 }
46 return;
47}
48