#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
srand(time(NULL));
const int N = 3;
int a[N][N];
int b[N][N];
int result[N][N];
int i = 0;
int j = 0;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++) {
a[i][j] = rand() % 10;
b[i][j] = rand() % 10;
result[i][j] = 0;
}
printf("First matrix:\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
printf("%d ", a[i][j]);
printf("\n");
}
printf("Second matrix:\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
printf("%d ", b[i][j]);
printf("\n");
}
int k = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
result[i][j] += a[i][k] * b[k][j];
printf("\nResult:\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
printf("%d ", result[i][j]);
printf("\n");
}
return 0;
}
Comments
Leave a comment