mirror of
https://github.com/lucaspalomodevelop/cpp_stuff.git
synced 2026-03-12 22:47:22 +00:00
add matrix_product
This commit is contained in:
parent
6e2edbdd96
commit
9bca440efd
36
matrix_product/main.cpp
Normal file
36
matrix_product/main.cpp
Normal 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
5
matrix_product/makefile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
dev: compile run
|
||||||
|
compile:
|
||||||
|
g++ -o matrix main.cpp
|
||||||
|
run:
|
||||||
|
./matrix
|
||||||
BIN
matrix_product/matrix
Executable file
BIN
matrix_product/matrix
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user