add matrix_product

This commit is contained in:
lucaspalomodevelop 2022-11-16 20:54:53 +01:00
parent 6e2edbdd96
commit 9bca440efd
3 changed files with 41 additions and 0 deletions

36
matrix_product/main.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <array>
#include <iostream>
int main()
{
int aMatrix[3][2] = {{1, 4}, {2, 5}, {3, 6}};
int bMatrix[2][3] = {{7, 8, 9}, {10, 11, 12}};
int product[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
for (int temp = 0; temp < 2; temp++)
{
product[row][col] += aMatrix[row][temp] * bMatrix[temp][col];
/* code */
}
if (row == 0 && col == 0)
{
std::cout << "Product:\n";
std::cout << product[row][col] << " ";
}
else
{
std::cout << product[row][col] << " ";
}
}
std::cout << "\n";
}
return 0;
}

5
matrix_product/makefile Normal file
View File

@ -0,0 +1,5 @@
dev: compile run
compile:
g++ -o matrix main.cpp
run:
./matrix

BIN
matrix_product/matrix Executable file

Binary file not shown.