Created
February 8, 2022 23:54
-
-
Save doylemark/ad55af4a21176ecc046915b24dad4b43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <stdlib.h> | |
typedef struct matrix | |
{ | |
size_t size; | |
int** values; | |
} matrix_t; | |
matrix_t make_matrix(double n, int lim, double p) | |
{ | |
size_t n_rows = lim - 1; | |
int** result = malloc(n_rows * sizeof(int*)); | |
if (result == NULL) | |
exit(1); | |
int max = 0; | |
int i = 0; | |
do | |
{ | |
result[i] = malloc(3 * sizeof(int)); | |
for (int j = 0; j < 3; j++) | |
{ | |
max = j + i; | |
result[i][j] = pow(n + max, p); | |
} | |
i += 1; | |
} | |
while (i <= lim && max < lim); | |
matrix_t m; | |
m.size = n_rows; | |
m.values = result; | |
return m; | |
} | |
void print_matrix(matrix_t* m) | |
{ | |
for (int i = 0; i < m->size; i++) | |
{ | |
for (int j = 0; j < 3; j++) | |
{ | |
printf("%d ", m->values[i][j]); | |
} | |
printf("\n"); | |
} | |
} | |
matrix_t multiply_matrix(matrix_t* a, matrix_t* b) | |
{ | |
int** result = malloc(a->size * sizeof(int*)); | |
for (int i = 0; i < a->size; i++) | |
{ | |
result [i] = malloc(3 * sizeof(int*)); | |
for (int j = 0; j < 3; j++) | |
{ | |
for (int k = 0; k < 3; k++) | |
{ | |
result[i][j] += a->values[i][k] * b->values[k][j]; | |
} | |
} | |
} | |
matrix_t m; | |
m.size = a->size; | |
m.values = result; | |
return m; | |
} | |
int main() | |
{ | |
int n; | |
scanf("%d", &n); | |
matrix_t a = make_matrix(n, 3, 2); | |
matrix_t b = make_matrix(n, 4, 3); | |
matrix_t m = multiply_matrix(&a, &b); | |
print_matrix(&m); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment